<?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: flag youngest and oldest 3 records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692835#M211149</link>
    <description>PROC RANK gives the user control over how ties are handled, which seems important in this example. PROC Sort does not give the user control over ties.</description>
    <pubDate>Tue, 20 Oct 2020 12:28:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-20T12:28:31Z</dc:date>
    <item>
      <title>flag youngest and oldest 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692730#M211092</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I have data as below and want to flag youngest 3 and oldest 3 records as shown in the screenshot below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any efficient way to do this ?&lt;/P&gt;&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length name $8 sex $1;
input name  sex    age  ;
cards ;
Joyce F 5
Thomas M 6
James M 12
Jane F 3
John M 12
Louise F 4
Robert M 12
Alice F 11
Barbara F 6
Jeffrey M 8
Alfred M 1
Carol F 16
Henry M 11
Judy F 8
Janet F 7
Mary F 12
Ronald M 13
William M 5
Philip M 8
;
run;

proc sort data=have ; by age ; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Want as below--&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="WANT" style="width: 338px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50810iFB06082BFF47F53F/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="WANT" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;WANT&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 02:28:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692730#M211092</guid>
      <dc:creator>chetan3125</dc:creator>
      <dc:date>2020-10-20T02:28:37Z</dc:date>
    </item>
    <item>
      <title>Re: flag youngest and oldest 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692732#M211093</link>
      <description>&lt;P&gt;PROC RANK is one option for this:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1hxon9vm350ikn19oeualfap8qy.htm&amp;amp;locale=en"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=proc&amp;amp;docsetTarget=n1hxon9vm350ikn19oeualfap8qy.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 02:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692732#M211093</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-20T02:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: flag youngest and oldest 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692829#M211144</link>
      <description>&lt;PRE&gt;data have;
length name $8 sex $1;
input name  sex    age  ;
cards ;
Joyce F 5
Thomas M 6
James M 12
Jane F 3
John M 12
Louise F 4
Robert M 12
Alice F 11
Barbara F 6
Jeffrey M 8
Alfred M 1
Carol F 16
Henry M 11
Judy F 8
Janet F 7
Mary F 12
Ronald M 13
William M 5
Philip M 8
;
run;

proc sort data=have ; by age ; run;
data temp;
 set have end=last;
 by age;
 n+first.age;
 if last then call symputx('n',n);
run;
data want;
 set temp;
 if n in (1 2 3) then youngest3=1;
 if n in (%eval(&amp;amp;n-2) %eval(&amp;amp;n-1) &amp;amp;n) then oldest3=1;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Oct 2020 12:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692829#M211144</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-20T12:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: flag youngest and oldest 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692835#M211149</link>
      <description>PROC RANK gives the user control over how ties are handled, which seems important in this example. PROC Sort does not give the user control over ties.</description>
      <pubDate>Tue, 20 Oct 2020 12:28:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/flag-youngest-and-oldest-3-records/m-p/692835#M211149</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-20T12:28:31Z</dc:date>
    </item>
  </channel>
</rss>

