<?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: retain multiple variables within group in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412795#M19850</link>
    <description>&lt;P&gt;Not easy to understand the question. Maybe this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ count date :mmddyy10.;
format date yymmdd10.;
datalines;
aa 1 01/20/2014
aa 2 03/24/2015
aa 3 04/23/2015
bb 1 10/23/2013
bb 2 03/24/2015
cc 3 08/10/2014
dd . . 
dd 2 05/19/2014
ee 1 03/02/2014
ee 2 03/19/2013
ee 3 04/23/2015
ee 4 10/12/2015
;

data want;
array date_r{3};
format date_r: yymmdd10.;
do i = 1 by 1 until(last.id);
    set have; by id;
    output;
    if i &amp;lt;= dim(date_r) then date_r{i} = date;
    end;
drop i;
run;

proc print noobs; var id count date date_r1-date_r3; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Nov 2017 05:01:44 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-11-13T05:01:44Z</dc:date>
    <item>
      <title>retain multiple variables within group</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412721#M19847</link>
      <description>&lt;P&gt;Hi SAS community-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to retain multiple variables within groups.&amp;nbsp; I can figure out how to retain 1 variable, but cannot get my code to do the 2nd variable in the way that I would like within groups.&amp;nbsp; Here's&amp;nbsp;current sas code along with my 'want' dataset. My starting dataset has&amp;nbsp;just the 3 variables: id, count and date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=have; by id;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;retain date_r1-date_r3;&lt;/P&gt;&lt;P&gt;if first.id then date_r1=date;&lt;/P&gt;&lt;P&gt;????&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input id count&amp;nbsp;date date_r1 date_r2 date_r3;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;aa 1 01/20/2014 . . .&lt;/P&gt;&lt;P&gt;aa 2 03/24/2015 01/20/2014 . .&lt;/P&gt;&lt;P&gt;aa 3 04/23/2015 01/20/2014 03/24/2015 .&lt;/P&gt;&lt;P&gt;bb 1 10/23/2013 . . .&lt;/P&gt;&lt;P&gt;bb 2 03/24/2015 10/23/2013 . .&lt;/P&gt;&lt;P&gt;cc 3 08/10/2014 . . .&lt;/P&gt;&lt;P&gt;dd . . . . .&lt;/P&gt;&lt;P&gt;dd 2 05/19/2014 . . .&lt;/P&gt;&lt;P&gt;ee&amp;nbsp;1 03/02/2014 . . .&lt;/P&gt;&lt;P&gt;ee 2 03/19/2013 03/02/2014 . .&lt;/P&gt;&lt;P&gt;ee 3 04/23/2015 03/02/2014 03/19/2013 .&lt;/P&gt;&lt;P&gt;ee 4 10/12/2015 03/02/2014 03/19/2013 04/23/2015&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 20:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412721#M19847</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2017-11-12T20:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: retain multiple variables within group</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412755#M19848</link>
      <description>&lt;P&gt;Not sure without seeing the desired data set ( WANT). Simple&amp;nbsp; use of "????" does not show what you need. Will it work if you use a DO - satement like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if first.id then DO;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; date_r1=date;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; date_r2 = date; /* NOT SURE WHAT IS TO BE ASSIGNED */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; date_r3 = date;&amp;nbsp;/* NOT SURE WHAT IS TO BE ASSIGNED */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;END;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 00:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412755#M19848</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2017-11-13T00:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: retain multiple variables within group</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412756#M19849</link>
      <description>&lt;P&gt;It is not clear what output you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ususally I declare RETAIN with new-temporary variable names.&lt;/P&gt;
&lt;P&gt;It is useles to declare retain of input variable name, like yours date_r1 - date_r3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, you can assign more then one retained variable, using DO statement,&lt;/P&gt;
&lt;P&gt;something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
   by id;
        retain var1 - var3;
       if first.id then do;
           var1 = date_r1;
           var2 = date_r2;
           var3 = date_r3;
      end;
       else do;    /* 2nd to last obs in a group */
           ......
       end;
      if last.id then output;    /* or any other function(s) */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please post yout desired output, in order to get more efficient code.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 00:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412756#M19849</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-13T00:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: retain multiple variables within group</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412795#M19850</link>
      <description>&lt;P&gt;Not easy to understand the question. Maybe this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ count date :mmddyy10.;
format date yymmdd10.;
datalines;
aa 1 01/20/2014
aa 2 03/24/2015
aa 3 04/23/2015
bb 1 10/23/2013
bb 2 03/24/2015
cc 3 08/10/2014
dd . . 
dd 2 05/19/2014
ee 1 03/02/2014
ee 2 03/19/2013
ee 3 04/23/2015
ee 4 10/12/2015
;

data want;
array date_r{3};
format date_r: yymmdd10.;
do i = 1 by 1 until(last.id);
    set have; by id;
    output;
    if i &amp;lt;= dim(date_r) then date_r{i} = date;
    end;
drop i;
run;

proc print noobs; var id count date date_r1-date_r3; run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Nov 2017 05:01:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/412795#M19850</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-13T05:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: retain multiple variables within group</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/413016#M19851</link>
      <description>&lt;P&gt;Thank you! This is exactly what I was looking for in the code.&amp;nbsp; Apologies for the lack of clarity in my initial post.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 19:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/retain-multiple-variables-within-group/m-p/413016#M19851</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2017-11-13T19:20:03Z</dc:date>
    </item>
  </channel>
</rss>

