<?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 the second date for each id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630958#M186865</link>
    <description>&lt;P&gt;Are you sure of the results for&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="token number"&gt;01&lt;/SPAN&gt;JAN2015&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="token number"&gt;18&lt;/SPAN&gt;FEB2015&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start;
attrib start format =date9. informat=date9.;

datalines;
1 01JAN2015 
1 18FEB2015 
2 01jan2015 
2 01apr2015 
3 01JAN2015 
3 01JAN2015 
;
run;

data want;
 do _n_=1 by 1 until(last.id);
  set test;
  by id;
  if _n_=2 then output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Mar 2020 15:29:56 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-03-10T15:29:56Z</dc:date>
    <item>
      <title>retain the second date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630955#M186863</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start;
attrib start format =date9. informat=date9.;

datalines;
1 01JAN2015 
1 18FEB2015 
2 01jan2015 
2 01apr2015 
3 01JAN2015 
3 01JAN2015 
;&lt;BR /&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I want to retain the second date for each id: output data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;1 18FEB2015&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;2 01apr2015&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;3 01JAN2015&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 15:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630955#M186863</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2020-03-10T15:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: retain the second date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630958#M186865</link>
      <description>&lt;P&gt;Are you sure of the results for&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="token number"&gt;01&lt;/SPAN&gt;JAN2015&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class="token number"&gt;18&lt;/SPAN&gt;FEB2015&lt;/CODE&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start;
attrib start format =date9. informat=date9.;

datalines;
1 01JAN2015 
1 18FEB2015 
2 01jan2015 
2 01apr2015 
3 01JAN2015 
3 01JAN2015 
;
run;

data want;
 do _n_=1 by 1 until(last.id);
  set test;
  by id;
  if _n_=2 then output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 15:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630958#M186865</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T15:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: retain the second date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630959#M186866</link>
      <description>&lt;P&gt;To be safe, in an event of having only 1 record per id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start;
attrib start format =date9. informat=date9.;

datalines;
1 01JAN2015 
1 18FEB2015 
2 01jan2015 
2 01apr2015 
3 01JAN2015 
3 01JAN2015 
;
run;

data want;
 do _n_=1 by 1 until(last.id);
  set test;
  by id;
  if first.id and last.id then output;
  else if _n_=2 then output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Mar 2020 15:31:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630959#M186866</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-10T15:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: retain the second date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630968#M186873</link>
      <description>&lt;P&gt;You've already chosen&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s solution.&amp;nbsp; As a slight conceptual change (from explicit loop to the hidden implicit loop), consider this analog:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  if first.id=0  and lag(first.id)=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, this approach is not as neatly extensible to higher order dates.&amp;nbsp; Here's what it would look like for say, the 4th date of each id:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  if max(first.id,lag(first.id),lag2(first.id))=0 and lag3(first.id)=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 15:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/630968#M186873</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-10T15:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: retain the second date for each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/631121#M186937</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72105"&gt;@lillymaginta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id$2. start;
attrib start format =date9. informat=date9.;

datalines;
1 01JAN2015 
1 18FEB2015 
2 01jan2015 
2 01apr2015 
3 01JAN2015 
3 01JAN2015 
;&lt;BR /&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;I want to retain the second date for each id: output data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;1 18FEB2015&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;2 01apr2015&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;3 01JAN2015&lt;/CODE&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Are you absolutely positive that there are &lt;STRONG&gt;never&lt;/STRONG&gt; more than 2 records for each id?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are there other variables that have to be brought along? If not perhaps:&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class id;
   var  start;
   output out=want (drop=_:) max=;
run;&lt;/PRE&gt;
&lt;P&gt;which may also handle the issue of more than 2 records assuming the actual latest date value is desired and not order position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 22:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/retain-the-second-date-for-each-id/m-p/631121#M186937</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-10T22:12:37Z</dc:date>
    </item>
  </channel>
</rss>

