<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic summarize diagnosis multiple columns and multiple per patients in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261144#M50757</link>
    <description>&lt;P&gt;Hi I have the following dataset: I wan to create a table that summarizes dx1-dx4 by the diagnosis regardless of the "date" where each dx per patient can only appear one. or example. patient3 has 3 diagnosis of 250, I want this to be counted as only 1 "250"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;patientid    dx1 dx2 dx3 dx4      date 
1               250 223 224 444    5/5/2009 
1               555 666 120 250    5/6/2008 
2               120  666                 1/2/2007 
2               120  666                 1/1/2007 
3               250                        2/2/2004
3               240 250                      3/3/2004 
3               250                          1/1/2004 &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The summary table should look like this:&lt;/P&gt;&lt;P&gt;dx &amp;nbsp; freq&lt;/P&gt;&lt;P&gt;223 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;224 1&lt;/P&gt;&lt;P&gt;120 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;250 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2016 17:27:50 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2016-04-04T17:27:50Z</dc:date>
    <item>
      <title>summarize diagnosis multiple columns and multiple per patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261144#M50757</link>
      <description>&lt;P&gt;Hi I have the following dataset: I wan to create a table that summarizes dx1-dx4 by the diagnosis regardless of the "date" where each dx per patient can only appear one. or example. patient3 has 3 diagnosis of 250, I want this to be counted as only 1 "250"&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;patientid    dx1 dx2 dx3 dx4      date 
1               250 223 224 444    5/5/2009 
1               555 666 120 250    5/6/2008 
2               120  666                 1/2/2007 
2               120  666                 1/1/2007 
3               250                        2/2/2004
3               240 250                      3/3/2004 
3               250                          1/1/2004 &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The summary table should look like this:&lt;/P&gt;&lt;P&gt;dx &amp;nbsp; freq&lt;/P&gt;&lt;P&gt;223 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;224 1&lt;/P&gt;&lt;P&gt;120 &amp;nbsp;1&lt;/P&gt;&lt;P&gt;250 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 17:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261144#M50757</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-04-04T17:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: summarize diagnosis multiple columns and multiple per patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261158#M50765</link>
      <description>&lt;P&gt;Assuming your example result miscounted Dx 120 (patient 1 and patient 2) this works for your example data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm treating the Dx codes as numeric to simplify reading since you didn't provide a data step to generate data and ignoring dates as there was no apparent need for date in the requested summary.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input patientid    dx1 dx2 dx3 dx4   ;
datalines;
1               250 223 224 444    5/5/2009 
1               555 666 120 250    5/6/2008 
2               120  666  .  .     1/2/2007 
2               120  666  .  .     1/1/2007 
3               250   .   .  .     2/2/2004 
3               240 250   .  .     3/3/2004 
3               250  .    .  .     1/1/2004 
;
run;

data trans (keep=patientid Dx);
   set have;
   array d Dx1-dx4;
   do i=1 to dim (d);
      Dx = d[i];
      if not missing(Dx) then output;
   end;
run;

Proc sql;
   select dx, count(dx) as freq
   from (select distinct patientid, dx from trans)
   group by dx;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 15:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261158#M50765</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-05T15:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: summarize diagnosis multiple columns and multiple per patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261162#M50767</link>
      <description>&lt;P&gt;So I believe I created what you are looking for. &amp;nbsp;I turned it into a macro just in case if you have more diagnoses spots than you originally specified. &amp;nbsp;Let me know if you have any questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE; &lt;BR /&gt;INPUT patientid 1-2 dx1 3-5 dx2 7-9 dx3 11-13 dx4 15-17 date mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 250 223 224 444 5/5/2009 &lt;BR /&gt;1 555 666 120 250 5/6/2008 &lt;BR /&gt;2 120 666 1/2/2007 &lt;BR /&gt;2 120 666 1/1/2007 &lt;BR /&gt;3 250 2/2/2004&lt;BR /&gt;3 240 250 3/3/2004 &lt;BR /&gt;3 250 1/1/2004 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SORT DATA = HAVE; &lt;BR /&gt; BY PatientID; &lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO FREQ (END = ); &lt;BR /&gt; %DO i = 1 %TO &amp;amp;END; &lt;BR /&gt; PROC FREQ DATA = HAVE NOPRINT; &lt;BR /&gt; TABLES PATIENTID*DX&amp;amp;i / OUT = FREQ_DX&amp;amp;i; &lt;BR /&gt; RUN; &lt;BR /&gt; DATA FREQ_DX&amp;amp;i; &lt;BR /&gt; SET FREQ_DX&amp;amp;i(RENAME = (COUNT = COUNT&amp;amp;i DX&amp;amp;i = DX));&lt;BR /&gt; DROP PERCENT;&lt;BR /&gt; RUN; &lt;BR /&gt; PROC SORT DATA = FREQ_DX&amp;amp;i; &lt;BR /&gt; BY PatientID DX;&lt;BR /&gt; RUN;&lt;BR /&gt; %END; &lt;BR /&gt; DATA ALMOST; &lt;BR /&gt; MERGE FREQ_DX1-FREQ_DX&amp;amp;END; &lt;BR /&gt; BY PatientID DX; &lt;BR /&gt; RUN; &lt;BR /&gt; PROC FREQ DATA = ALMOST; &lt;BR /&gt; TABLES DX / OUT = WANT; &lt;BR /&gt; RUN;&lt;BR /&gt;%MEND;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%FREQ(END=4);&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2016 18:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261162#M50767</guid>
      <dc:creator>Katie</dc:creator>
      <dc:date>2016-04-04T18:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: summarize diagnosis multiple columns and multiple per patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261448#M50889</link>
      <description>&lt;P&gt;Thank you. This worked well. Would it be possible to have the output in order descending or ascending?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 15:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261448#M50889</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-04-05T15:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: summarize diagnosis multiple columns and multiple per patients</title>
      <link>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261449#M50890</link>
      <description>&lt;P&gt;Thank you for taking the time to write the macro. Both methods gave me the same answer, I really apprecaite it!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 15:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/summarize-diagnosis-multiple-columns-and-multiple-per-patients/m-p/261449#M50890</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-04-05T15:40:30Z</dc:date>
    </item>
  </channel>
</rss>

