<?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 carry forword values both up and down rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642485#M191677</link>
    <description>&lt;P&gt;Hi experts, i have a dataset like below&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;input subjid 1-6 type 8 status 10 eventdate 12-19 ;&lt;BR /&gt;cards;&lt;BR /&gt;150004 1 . 2015-08-19&lt;BR /&gt;150004 2 1&lt;BR /&gt;180016 2 .&lt;BR /&gt;180016 1 . 2015-04-03&lt;BR /&gt;180020 1 1 .&lt;BR /&gt;180020 2 . 2015-08-20&lt;BR /&gt;180041 1 1 .&lt;BR /&gt;180041 1 . 2015-02-09&lt;BR /&gt;190004 1 1 .&lt;BR /&gt;100033 1 . 2017-01-26&lt;BR /&gt;100033 2 1 .&lt;BR /&gt;160071 1 1 .&lt;BR /&gt;160071 2 . 2016-02-28&lt;BR /&gt;460088 1 1 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;i would like to make the final dataset with single observation for each subjid and if status,eventdate not missing for a perticular subjid then do status="Y", finaldate=eventdate;&lt;/P&gt;
&lt;P&gt;Though i have found a way such as by doing a transpose and then writing a if statement to do the procedure, but looking from experts POV if there is a way to carryforword values both uprow (eg:for subjid 180016 )and downrow(as required 150004 ) the values based on a retain and by last. statement to solve/ any other efficient programming way this then it would be helpful to hear from you,experts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Apr 2020 09:00:10 GMT</pubDate>
    <dc:creator>sahoositaram555</dc:creator>
    <dc:date>2020-04-24T09:00:10Z</dc:date>
    <item>
      <title>carry forword values both up and down rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642485#M191677</link>
      <description>&lt;P&gt;Hi experts, i have a dataset like below&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;input subjid 1-6 type 8 status 10 eventdate 12-19 ;&lt;BR /&gt;cards;&lt;BR /&gt;150004 1 . 2015-08-19&lt;BR /&gt;150004 2 1&lt;BR /&gt;180016 2 .&lt;BR /&gt;180016 1 . 2015-04-03&lt;BR /&gt;180020 1 1 .&lt;BR /&gt;180020 2 . 2015-08-20&lt;BR /&gt;180041 1 1 .&lt;BR /&gt;180041 1 . 2015-02-09&lt;BR /&gt;190004 1 1 .&lt;BR /&gt;100033 1 . 2017-01-26&lt;BR /&gt;100033 2 1 .&lt;BR /&gt;160071 1 1 .&lt;BR /&gt;160071 2 . 2016-02-28&lt;BR /&gt;460088 1 1 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;i would like to make the final dataset with single observation for each subjid and if status,eventdate not missing for a perticular subjid then do status="Y", finaldate=eventdate;&lt;/P&gt;
&lt;P&gt;Though i have found a way such as by doing a transpose and then writing a if statement to do the procedure, but looking from experts POV if there is a way to carryforword values both uprow (eg:for subjid 180016 )and downrow(as required 150004 ) the values based on a retain and by last. statement to solve/ any other efficient programming way this then it would be helpful to hear from you,experts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642485#M191677</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-24T09:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: carry forword values both up and down rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642499#M191680</link>
      <description>&lt;P&gt;Please test your data step and correct it.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 09:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642499#M191680</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-24T09:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: carry forword values both up and down rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642507#M191686</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, Thanks for the pick.&lt;BR /&gt;data a;&lt;BR /&gt;infile datalines missover; &lt;BR /&gt;input subjid type status eventdate ;&lt;/P&gt;
&lt;P&gt;format eventdate YYMMDD10.;&lt;BR /&gt;datalines;&lt;BR /&gt;150004 1 . 20181&lt;BR /&gt;150004 2 1&lt;BR /&gt;180016 2 .&lt;BR /&gt;180016 1 . 20320&lt;BR /&gt;180020 1 1 .&lt;BR /&gt;180020 2 . 20128&lt;BR /&gt;180041 1 1 .&lt;BR /&gt;180041 1 . 20473&lt;BR /&gt;190004 1 1 .&lt;BR /&gt;100033 1 . 20502&lt;BR /&gt;100033 2 1 .&lt;BR /&gt;160071 1 1 .&lt;BR /&gt;160071 2 . 20913&lt;BR /&gt;460088 1 1 20942&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 10:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642507#M191686</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-04-24T10:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: carry forword values both up and down rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642515#M191691</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
infile datalines missover; 
input subjid type status eventdate ;
format eventdate YYMMDD10.;
datalines;
150004 1 . 20181
150004 2 1
180016 2 .
180016 1 . 20320
180020 1 1 .
180020 2 . 20128
180041 1 1 .
180041 1 . 20473
190004 1 1 .
100033 1 . 20502
100033 2 1 .
160071 1 1 .
160071 2 . 20913
460088 1 1 20942
;

data want;
set a (rename=(status=_status));
by subjid notsorted;
retain status finaldate;
format status $1. finaldate yymmddd10.;
if first.subjid
then do;
  status = "";
  finaldate = .;
end;
status = ifc(_status,'Y',status);
finaldate = coalesce(finaldate,eventdate);
if last.subjid;
keep subjid status finaldate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 11:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642515#M191691</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-24T11:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: carry forword values both up and down rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642606#M191726</link>
      <description>&lt;P&gt;If you only want one observation per SUBJID there is not need to look ahead (or back).&amp;nbsp; Just aggregate over the subjid.&lt;/P&gt;
&lt;P&gt;SQL is very good at that.&lt;/P&gt;
&lt;P&gt;Your rules are not that clear so if this result is not what you want then explain the rules more clearly and provide the output you want for this input.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input subjid type status eventdate :yymmdd. ;
  format eventdate YYMMDD10.;
datalines;
100033 1 . 2016-02-18
100033 2 1 .
150004 1 . 2015-04-03
150004 2 1 .
160071 1 1 .
160071 2 . 2017-04-04
180016 2 . .
180016 1 . 2015-08-20
180020 1 1 .
180020 2 . 2015-02-09
180041 1 1 .
180041 1 . 2016-01-20
190004 1 1 .
460088 1 1 2017-05-03
;

proc sql ;
  select subjid,max(status) as status
       , max(eventdate) as finaldate format=yymmdd10.
  from a
  group by subjid
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;  subjid    status   finaldate
------------------------------
  100033         1  2016-02-18
  150004         1  2015-04-03
  160071         1  2017-04-04
  180016         .  2015-08-20
  180020         1  2015-02-09
  180041         1  2016-01-20
  190004         1           .
  460088         1  2017-05-03
&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/carry-forword-values-both-up-and-down-rows/m-p/642606#M191726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-24T14:21:10Z</dc:date>
    </item>
  </channel>
</rss>

