<?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 Re: How to analyze patient ID with multiple diagnosis rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851878#M336733</link>
    <description>&lt;P&gt;Thank you so much, Kurt and happy new year.&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;I tried your suggested code but it gave me the below.&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="epiflo_0-1672702527100.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78987iBE907DFAE7992C0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="epiflo_0-1672702527100.png" alt="epiflo_0-1672702527100.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;I think my problem is getting the frequency number for the second diagnosis when some patients have 3 or more diagnosis. I am simply interested in the initial 0 and the second using the diagnosis year.. As I mentioned the first diagnosis for all patients is a 0 and the second diagnosis will either will be a 0 or 1.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="epiflo_1-1672702527100.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78988iF52B7393FEED0B8E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="epiflo_1-1672702527100.png" alt="epiflo_1-1672702527100.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I generate the following table? For example this is the ideal output I am looking for with made-up numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Behavior of 2nd diagnosis&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Frequency&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;211&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;44.99&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;258&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;55.01&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your help. I hope this clarifies further..&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Jan 2023 23:37:10 GMT</pubDate>
    <dc:creator>epiflo</dc:creator>
    <dc:date>2023-01-02T23:37:10Z</dc:date>
    <item>
      <title>How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851157#M336386</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to get some frequency numbers for two patient populations:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pop 1 : Patients who have an initial&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;behavior code of 0 followed by behavior code 1 based on year of diagnosis (yod).&lt;/P&gt;&lt;P&gt;Pop 2: Patients who have an initial behavior code of 0 followed by behavior code 1 based on diagnosis (yod).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some patients have up to 6 diagnosis but I am only interested in the first 2 as explained above based on the yod.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would you code this given I have multiple diagnosis (behavior_code) and different yod to obtain the n’s for each population?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of some of the variables I am working with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;patient_id&lt;/TD&gt;&lt;TD&gt;age&lt;/TD&gt;&lt;TD&gt;yod&lt;/TD&gt;&lt;TD&gt;behavior_code&lt;/TD&gt;&lt;TD&gt;det_sequence_no&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;55-59 years&lt;/TD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lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;50-54 years&lt;/TD&gt;&lt;TD&gt;2009&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;60-64 years&lt;/TD&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2022 20:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851157#M336386</guid>
      <dc:creator>epiflo</dc:creator>
      <dc:date>2022-12-26T20:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851159#M336388</link>
      <description>&lt;P&gt;All your patients have a 0 followed by a 1, so they all fall into the same group.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2022 22:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851159#M336388</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-26T22:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851166#M336392</link>
      <description>Hello Kurt-&lt;BR /&gt;Thank you for the response, actually, the data I provided is a small set&lt;BR /&gt;from the almost 50K observations I have. Some of the patients have multiple&lt;BR /&gt;diagnoses of either a 0 or 1. All patients start with a diagnosis of 0 but&lt;BR /&gt;then I guess you can say they recur by either developing a 0 or 1 so I am&lt;BR /&gt;trying to figure out how to obtain the count for:&lt;BR /&gt;number of patients that initially present with a diagnosis of 0 and then&lt;BR /&gt;develop another 0&lt;BR /&gt;and the&lt;BR /&gt;number of patients that initially present with a diagnosis of 0 and then&lt;BR /&gt;develop a 1.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 27 Dec 2022 05:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851166#M336392</guid>
      <dc:creator>epiflo</dc:creator>
      <dc:date>2022-12-27T05:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851171#M336396</link>
      <description>&lt;P&gt;So you want to count patients with a 0/1 combination in the first two observations vs. those with a 0/0, and disregard all further observations for each patient?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by patient_id;
if first.patient_id
then count = 1;
else count + 1;
beh = lag(behavior_code);
if count = 2;
if not beh
then if behavior_code
  then flag = 1;
  else flag = 0;
keep patient_id flag;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Should a patient start with 1, flag will be missing.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2022 06:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851171#M336396</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-27T06:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851176#M336398</link>
      <description>&lt;P&gt;I don't understand the difference between Pop1 and Pop2. If the code posted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; does not solve the issue, you need to post example data containing all possible combinations and show the expected result for that dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2022 07:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851176#M336398</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-12-27T07:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851878#M336733</link>
      <description>&lt;P&gt;Thank you so much, Kurt and happy new year.&lt;SPAN class=""&gt;&amp;nbsp; &lt;/SPAN&gt;I tried your suggested code but it gave me the below.&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="epiflo_0-1672702527100.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78987iBE907DFAE7992C0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="epiflo_0-1672702527100.png" alt="epiflo_0-1672702527100.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;I think my problem is getting the frequency number for the second diagnosis when some patients have 3 or more diagnosis. I am simply interested in the initial 0 and the second using the diagnosis year.. As I mentioned the first diagnosis for all patients is a 0 and the second diagnosis will either will be a 0 or 1.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="epiflo_1-1672702527100.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78988iF52B7393FEED0B8E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="epiflo_1-1672702527100.png" alt="epiflo_1-1672702527100.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I generate the following table? For example this is the ideal output I am looking for with made-up numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Behavior of 2nd diagnosis&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Frequency&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;211&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;44.99&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;258&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;55.01&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for your help. I hope this clarifies further..&lt;SPAN class=""&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jan 2023 23:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851878#M336733</guid>
      <dc:creator>epiflo</dc:creator>
      <dc:date>2023-01-02T23:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851909#M336750</link>
      <description>&lt;P&gt;After making your data usable (always, as in&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;ALWAYS&lt;/U&gt;,&lt;/STRONG&gt; post your example data as data step code which creates the data), I get this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x dsd truncover;
input patient_id $ age :$15. yod behavior_code det_sequence_no;
datalines;
1	55-59 years	2011	0	1
1	60-64 years	2015	1	2
2	55-59 years	2001	0	1
2	55-59 years	2002	1	2
3	70-74 years	2002	0	1
3	75-79 years	2007	1	2
4	45-49 years	2003	0	1
4	50-54 years	2008	0	2
4	50-54 years	2009	1	3
4	60-64 years	2018	1	4
;

data want;
set have;
by patient_id;
label flag = "Behavior of 2nd Diagnosis";
if first.patient_id
then count = 1;
else count + 1;
beh = lag(behavior_code);
if count = 2;
if not beh
then if behavior_code
  then flag = 1;
  else flag = 0;
keep patient_id flag;
run;

/* The following step, taken from https://support.sas.com/kb/23/350.html,
   is only there to get the variable label for the variable column */
proc template;                                                                
   edit Base.Freq.OneWayList ;             
      edit h1; 
    /* set text to BLANK instead of VARLABEL */ 
         text " ";                                                            
      end;                                                   
                                                                              
      edit FVariable;                                                       
       just=varjust;
       style=rowheader;
       id;
       generic;
       header=varlabel;
      end;
   end;                                    
run;

proc freq data=want;
tables flag / nocum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which gets this result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2023-01-03 um 10.56.35.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/78996iA1E1EA67C40691C3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2023-01-03 um 10.56.35.png" alt="Bildschirmfoto 2023-01-03 um 10.56.35.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2023 09:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/851909#M336750</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-01-03T09:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to analyze patient ID with multiple diagnosis rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/852196#M336887</link>
      <description>Thank you, Kurt. This worked!</description>
      <pubDate>Wed, 04 Jan 2023 20:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-analyze-patient-ID-with-multiple-diagnosis-rows/m-p/852196#M336887</guid>
      <dc:creator>epiflo</dc:creator>
      <dc:date>2023-01-04T20:53:07Z</dc:date>
    </item>
  </channel>
</rss>

