<?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: About converting data from one row to multiple rows for Survival analysis in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/About-converting-data/m-p/839350#M331891</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id gender $ enrolldate : mmddyy. aaa : mmddyy. bbb : mmddyy. inflam_1 : mmddyy. inflam_2 : mmddyy. inflam_3 : mmddyy. @@;
format enrolldate aaa bbb inflam_1 inflam_2 inflam_3 mmddyy10.;
datalines;
1 M 08/01/2019 09/04/2019 09/16/2019 10/02/2019 11/03/2019 12/04/2019
2 M 08/02/2019 08/14/2019 . 06/25/2019 09/14/2019 .
3 F 08/03/2019 . . 10/13/2019 11/13/2019 .
4 F 08/04/2019 07/04/2019 09/16/2019 . . .
5 F 08/05/2019 05/04/2019 07/04/2019 09/18/2019 10/18/2019 .
;
run;

data temp;
 set have;
 by id;
 if first.id then group=0;

 length flag $ 40;
 min=min(enrolldate,aaa,bbb,inflam_1,inflam_2,inflam_3);
 do date=min to '31dec2019'd;
   if date=enrolldate then do;flag='enrolldate';group+1;end;
   if date=aaa then do;flag='aaa';group+1;end;
   if date=bbb then do;flag='bbb';group+1;end;
   if date=inflam_1 then do;flag='inflam_1';group+1;end;
   if date=inflam_2 then do;flag='inflam_2';group+1;end;
   if date=inflam_3 then do;flag='inflam_3';group+1;end;
   output;
 end;
 format date mmddyy10.;
 keep  id gender  flag date group;
run;
proc summary data=temp;
by id gender group flag;
var date ;
output out=temp2(drop=_:) min=start max=stop;
run;
data temp3;
 set temp2;
 by id;
 retain trt_status ;
 if first.id then trt_status=0;
 if flag='aaa' then trt_status=1;
 if flag='bbb' then trt_status=2;
run;
data temp4;
 merge temp3 temp3(keep=id flag rename=(id=_id flag=_flag) firstobs=2);
 inflam_event=0;
 if id=_id and _flag=:'inflam_' then inflam_event=1;

 retain inflam_count _count1 _count2;
 if id ne lag(id) then do;inflam_count=0;_count1=0;_count2=0;end;
 if flag=:'inflam_' then _count1=input(scan(flag,-1,'_'),best.);
 if id=_id and _flag=:'inflam_' then _count2=input(scan(_flag,-1,'_'),best.);
 inflam_count=max(_count1,_count2);
 drop _:;
run;
data temp5;
 set temp4;
 by id;
 retain prior_inflam ;
 if first.id then prior_inflam=0;
 if id=lag(id) and lag(inflam_count)=1 then prior_inflam=1;
run;
data temp6;
 set temp5;
 by id;
 retain found;
 if first.id then found=0;
 if flag='enrolldate' then found=1;
 if found;
run;
data want;
 set temp6(drop=group flag found);
 if stop ne '31dec2019'd then stop=stop+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Oct 2022 11:48:19 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-10-19T11:48:19Z</dc:date>
    <item>
      <title>About converting data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-converting-data/m-p/839309#M331863</link>
      <description>&lt;P&gt;Closed&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 14:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-converting-data/m-p/839309#M331863</guid>
      <dc:creator>hellorc</dc:creator>
      <dc:date>2022-10-19T14:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: About converting data from one row to multiple rows for Survival analysis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-converting-data/m-p/839350#M331891</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id gender $ enrolldate : mmddyy. aaa : mmddyy. bbb : mmddyy. inflam_1 : mmddyy. inflam_2 : mmddyy. inflam_3 : mmddyy. @@;
format enrolldate aaa bbb inflam_1 inflam_2 inflam_3 mmddyy10.;
datalines;
1 M 08/01/2019 09/04/2019 09/16/2019 10/02/2019 11/03/2019 12/04/2019
2 M 08/02/2019 08/14/2019 . 06/25/2019 09/14/2019 .
3 F 08/03/2019 . . 10/13/2019 11/13/2019 .
4 F 08/04/2019 07/04/2019 09/16/2019 . . .
5 F 08/05/2019 05/04/2019 07/04/2019 09/18/2019 10/18/2019 .
;
run;

data temp;
 set have;
 by id;
 if first.id then group=0;

 length flag $ 40;
 min=min(enrolldate,aaa,bbb,inflam_1,inflam_2,inflam_3);
 do date=min to '31dec2019'd;
   if date=enrolldate then do;flag='enrolldate';group+1;end;
   if date=aaa then do;flag='aaa';group+1;end;
   if date=bbb then do;flag='bbb';group+1;end;
   if date=inflam_1 then do;flag='inflam_1';group+1;end;
   if date=inflam_2 then do;flag='inflam_2';group+1;end;
   if date=inflam_3 then do;flag='inflam_3';group+1;end;
   output;
 end;
 format date mmddyy10.;
 keep  id gender  flag date group;
run;
proc summary data=temp;
by id gender group flag;
var date ;
output out=temp2(drop=_:) min=start max=stop;
run;
data temp3;
 set temp2;
 by id;
 retain trt_status ;
 if first.id then trt_status=0;
 if flag='aaa' then trt_status=1;
 if flag='bbb' then trt_status=2;
run;
data temp4;
 merge temp3 temp3(keep=id flag rename=(id=_id flag=_flag) firstobs=2);
 inflam_event=0;
 if id=_id and _flag=:'inflam_' then inflam_event=1;

 retain inflam_count _count1 _count2;
 if id ne lag(id) then do;inflam_count=0;_count1=0;_count2=0;end;
 if flag=:'inflam_' then _count1=input(scan(flag,-1,'_'),best.);
 if id=_id and _flag=:'inflam_' then _count2=input(scan(_flag,-1,'_'),best.);
 inflam_count=max(_count1,_count2);
 drop _:;
run;
data temp5;
 set temp4;
 by id;
 retain prior_inflam ;
 if first.id then prior_inflam=0;
 if id=lag(id) and lag(inflam_count)=1 then prior_inflam=1;
run;
data temp6;
 set temp5;
 by id;
 retain found;
 if first.id then found=0;
 if flag='enrolldate' then found=1;
 if found;
run;
data want;
 set temp6(drop=group flag found);
 if stop ne '31dec2019'd then stop=stop+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2022 11:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-converting-data/m-p/839350#M331891</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-19T11:48:19Z</dc:date>
    </item>
  </channel>
</rss>

