title: SAS Unique and Distinct- but need an additional variable as well
body: <p>I have a dataset that I'm trying to get a frequency from in SAS. Essentially there are a bunch of episodes and whether someone had an event. An episode could technically have more than one event. Each record also has an organization identifier. I've developed a code (below) that correctly identifies the frequency of events per episode (so for instance, 1, 2, and 3 events per episode):</p>
  
  <pre><code>proc sql;
      create table out as select unique
          episode_id, sum(event) as total_event
      from table1
      group by episode_id;
  quit; 
  
  proc freq data=out;
      tables total_event;
  run;
  </code></pre>
  
  <p>This code while great for giving me a quick frequency of the number of events per episode is missing a vital piece of information I need- namely the organization_id. Whenever I add organization_id to the code, the frequencies become wrong. I tried to merge back the out table to table1 to get the organization_id as well but that also adds to the frequency. How do I add an additional variable so that I can ultimately run the following frequency: </p>
  
  <pre><code>proc freq data=out;
  tables organization_id*total_event;
  run;
  </code></pre>