<?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: Transposing data following replacement of missing dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350582#M81500</link>
    <description>&lt;P&gt;Hi art297,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is a great solution.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;By the way, can you suggest me the way to address it using proc transpose. Just for my knowledge.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Deepak&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Apr 2017 17:26:23 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2017-04-17T17:26:23Z</dc:date>
    <item>
      <title>Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350552#M81493</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;For your kind information, I am having a datset with multiple intervention dates in each row which I want to transpose to get one intervention date per row. At the same time, as some of the intervention dates are missing, I want to replace with the missing intervention date with the admission date.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
id=1;  admission_date="20140102"; intervention_1=101 ; intervention_1_date="20140102" ; intervention_2=102 ; intervention_2_date="20140103" ; intervention_3=103 ; intervention_3_date="20140103" ;output;
id=2;  admission_date="20140102"; intervention_1=102 ; intervention_1_date="20140102" ; intervention_2=103 ; intervention_2_date="20140102" ; intervention_3=102 ; intervention_3_date="20140104" ;output;
id=3;  admission_date="20140103"; intervention_1=103 ; intervention_1_date="20140103" ; intervention_2=102 ; intervention_2_date=" " ; intervention_3=101 ; intervention_3_date="20140104" ;output;
id=4;  admission_date="20140104"; intervention_1=103 ; intervention_1_date=" " ; intervention_2=102 ; intervention_2_date="20140104" ; intervention_3=101 ; intervention_3_date="20140105" ;output;
run;


data want;
input id admission_date intervention intervention_date;
cards;
1 20140102 101 20140102
1 20140102 102 20140103
1 20140102 103 20140103
2 20140102 102 20140102
2 20140102 103 20140102
2 20140102 102 20140104
3 20140103 103 20140103
3 20140103 102 20140103
3 20140103 101 20140104
4 20140104 103 20140104
4 20140104 102 20140104
4 20140104 101 20140105
;
run;&lt;/PRE&gt;&lt;P&gt;Can somebody help me to solve the problem. Thank you in advance for your kind reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 15:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350552#M81493</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-17T15:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350565#M81495</link>
      <description>&lt;P&gt;Easiest to do with arrays. e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (keep=id admission_date intervention intervention_date);
  set have;
  array int(*) intervention_1-intervention_3;
  array intd(*) $ intervention_1_date intervention_1_date intervention_3_date;
  do i=1 to dim(int);
    intervention=int(i);
    intervention_date=coalescec(intd(i),admission_date);
    output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 16:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350565#M81495</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-17T16:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350567#M81497</link>
      <description>&lt;P&gt;Here's a way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array inter {4} intervention_1 - intervention_4;&lt;/P&gt;
&lt;P&gt;array interdt {4} intervention_1_date intervention_2_date intervention_3_date intervention_4_date;&lt;/P&gt;
&lt;P&gt;do i=1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;intervention = inter{i};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;intervention_date = interdt{i};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if intervention_date = ' ' then intervention_date = admission_date;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;keep id admission_date intervention intervention_date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 16:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350567#M81497</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-17T16:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350570#M81498</link>
      <description>&lt;P&gt;PLease try the arrays which is more easier&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
id=1;  admission_date="20140102"; intervention_1=101 ; intervention_1_date="20140102" ; intervention_2=102 ; intervention_2_date="20140103" ; intervention_3=103 ; intervention_3_date="20140103" ;output;
id=2;  admission_date="20140102"; intervention_1=102 ; intervention_1_date="20140102" ; intervention_2=103 ; intervention_2_date="20140102" ; intervention_3=102 ; intervention_3_date="20140104" ;output;
id=3;  admission_date="20140103"; intervention_1=103 ; intervention_1_date="20140103" ; intervention_2=102 ; intervention_2_date=" " ; intervention_3=101 ; intervention_3_date="20140104" ;output;
id=4;  admission_date="20140104"; intervention_1=103 ; intervention_1_date=" " ; intervention_2=102 ; intervention_2_date="20140104" ; intervention_3=101 ; intervention_3_date="20140105" ;output;
run;

data have2;
set have;
by id admission_date;
array misd(3) intervention_1_date intervention_2_date intervention_3_date;
array misi(3) intervention_1 -intervention_3;
do i = 1 to 3;
if misd(i)='' then misd(i)=admission_date;
end;
do j= 1 to 3;
if misd(j) ne '' then do;
intervention_date=misd(j);
intervention_id=misi(j);
end;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Apr 2017 16:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350570#M81498</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-04-17T16:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350579#M81499</link>
      <description>Hi Astounding,&lt;BR /&gt;This is a great solution. Only correction, I did is the number of intervention from 4 to 3.&lt;BR /&gt;By the way, can you suggest me the way to address it using proc transpose. Just for my knowledge. Regards,</description>
      <pubDate>Mon, 17 Apr 2017 17:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350579#M81499</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-17T17:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350582#M81500</link>
      <description>&lt;P&gt;Hi art297,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is a great solution.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;By the way, can you suggest me the way to address it using proc transpose. Just for my knowledge.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Deepak&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 17:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350582#M81500</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-17T17:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350586#M81501</link>
      <description>&lt;P&gt;Only because you asked:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
id=1;  admission_date="20140102"; intervention_1=101 ; intervention_1_date="20140102" ; intervention_2=102 ; intervention_2_date="20140103" ; intervention_3=103 ; intervention_3_date="20140103" ;output;
id=2;  admission_date="20140102"; intervention_1=102 ; intervention_1_date="20140102" ; intervention_2=103 ; intervention_2_date="20140102" ; intervention_3=102 ; intervention_3_date="20140104" ;output;
id=3;  admission_date="20140103"; intervention_1=103 ; intervention_1_date="20140103" ; intervention_2=102 ; intervention_2_date=" " ; intervention_3=101 ; intervention_3_date="20140104" ;output;
id=4;  admission_date="20140104"; intervention_1=103 ; intervention_1_date=" " ; intervention_2=102 ; intervention_2_date="20140104" ; intervention_3=101 ; intervention_3_date="20140105" ;output;
run;

proc transpose data=have 
               out=one (drop=_: 
                        rename=(col1=intervention
                        intervention_1_date=intervention_date));
  by id admission_date;
  var intervention_1;
  copy intervention_1_date;
run;

proc transpose data=have 
               out=two (drop=_: 
                        rename=(col1=intervention
                        intervention_2_date=intervention_date));
  by id admission_date;
  var intervention_2;
  copy intervention_2_date;
run;

proc transpose data=have 
               out=three (drop=_: 
                        rename=(col1=intervention
                        intervention_3_date=intervention_date));
  by id admission_date;
  var intervention_3;
  copy intervention_3_date;
run;

data want;
  set one two three;
  intervention_date=coalescec(intervention_date,admission_date);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 17:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350586#M81501</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-17T17:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350617#M81514</link>
      <description>&lt;P&gt;Thanks art297.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 19:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350617#M81514</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-17T19:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350628#M81517</link>
      <description>&lt;P&gt;Since you already have a PROC TRANSPOSE solution, I would suggest another line of study. &amp;nbsp;When you are working with date variables, SAS has a preferred method of storing them that gives you great flexibility in displaying them and using them for calculations. &amp;nbsp;That would be a worthwhile area to spend some time.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 19:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350628#M81517</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-17T19:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350633#M81520</link>
      <description>&lt;P&gt;Hi Astounding,&lt;BR /&gt;Thanks for your advice. For your kind information, I am still trying to explore "Proc transpose" to transpose all 3 interventions to one column and all 3 intervention dates to another column without using array.&lt;/P&gt;&lt;P&gt;Till now what I learnt is transpose each intervention with associated with date and then use set. If I have large number of interventions, it becomes cumbersome process.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you suggest some efficient code to do that.&lt;/P&gt;&lt;P&gt;Thank you in advance for your kind reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2017 20:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350633#M81520</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-17T20:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing data following replacement of missing dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350813#M81602</link>
      <description>&lt;P&gt;Hi art297,&lt;/P&gt;&lt;P&gt;Thank you for taking the pain to answer my query. You have nicely addressed by issue using proc transpose. For 3 interventions, this approach is manageable. If I have 10 intervention-codes and &amp;nbsp;10 intervention-dates. Can you kindly guide me the way to transpose all 10 intervention-codes to one column and all 10 intervention-dates to another column using proc transpose. By the way, use of array and do loop adviced by you is "Great".&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 12:27:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-data-following-replacement-of-missing-dates/m-p/350813#M81602</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2017-04-18T12:27:38Z</dc:date>
    </item>
  </channel>
</rss>

