<?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: If first statements Part II in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119965#M33036</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="text-align: left;"&gt;Because FCODE is nested within SCHOOL within STUKEY, the groups are not necessarily 'FIRST' at the same time.&amp;nbsp; If FIRST.STUKEY is true, the other three must also be true.&amp;nbsp; But the reverse is not true.&lt;/P&gt;&lt;P&gt;Examine the output from the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=sashelp.class out=class;&lt;BR /&gt;by sex age;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data new(keep=sex age fsex fage);&lt;BR /&gt;set class;&lt;BR /&gt;by sex age;&lt;BR /&gt;fsex=first.sex;&lt;BR /&gt;fage=first.age;&lt;BR /&gt;run;&lt;/P&gt;&lt;DIV align="center"&gt; &lt;/DIV&gt;&lt;P&gt;proc print data=new;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV align="center"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Nov 2012 18:33:27 GMT</pubDate>
    <dc:creator>ArtC</dc:creator>
    <dc:date>2012-11-07T18:33:27Z</dc:date>
    <item>
      <title>If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119963#M33034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you to Reeza and Arthur for their help and explanation to my previous question.&amp;nbsp; I want to ask a follow-up.&amp;nbsp; What if I was to count the first observations for three different variables?&amp;nbsp; I want outputted the first stukey and first school and first fcode.&amp;nbsp; Could I do this?&amp;nbsp;&amp;nbsp; Would I always select the first dot of the last variable regardless of how many variables I select?&amp;nbsp; Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set enr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.fcode; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 18:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119963#M33034</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2012-11-07T18:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119964#M33035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you are asking.&amp;nbsp; Can you provide an example that shows what test looks like (i.e., with some example data preferably in the form of a datastep), as well as another table that shows the result of what you are trying to accomplish?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 18:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119964#M33035</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-07T18:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119965#M33036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="text-align: left;"&gt;Because FCODE is nested within SCHOOL within STUKEY, the groups are not necessarily 'FIRST' at the same time.&amp;nbsp; If FIRST.STUKEY is true, the other three must also be true.&amp;nbsp; But the reverse is not true.&lt;/P&gt;&lt;P&gt;Examine the output from the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=sashelp.class out=class;&lt;BR /&gt;by sex age;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data new(keep=sex age fsex fage);&lt;BR /&gt;set class;&lt;BR /&gt;by sex age;&lt;BR /&gt;fsex=first.sex;&lt;BR /&gt;fage=first.age;&lt;BR /&gt;run;&lt;/P&gt;&lt;DIV align="center"&gt; &lt;/DIV&gt;&lt;P&gt;proc print data=new;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV align="center"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 18:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119965#M33036</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-11-07T18:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119966#M33037</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a dataset with stukeys schools and fcodes.&amp;nbsp; I am interested in finding every different fcode for each stukey assigned by every school.&amp;nbsp;&amp;nbsp;&amp;nbsp; Okay here is the sample data:&lt;/P&gt;&lt;P&gt;Notice that in the text file, the very last record is a duplicate and I would expect the output to exclude that. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt; input stukey $ school $ fcode $;&lt;/P&gt;&lt;P&gt; cards;&lt;/P&gt;&lt;P&gt; 992346 20311 D&lt;/P&gt;&lt;P&gt; 992346 23659 C&lt;/P&gt;&lt;P&gt; 992346 20311 B&lt;/P&gt;&lt;P&gt; 992346 55236 A&lt;/P&gt;&lt;P&gt; 992346 20311 D&lt;/P&gt;&lt;P&gt; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my expected results:&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="192"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD align="right" height="17" width="64"&gt;992346&lt;/TD&gt;&lt;TD align="right" width="64"&gt;20311&lt;/TD&gt;&lt;TD width="64"&gt;D&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;992346&lt;/TD&gt;&lt;TD align="right"&gt;23659&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;992346&lt;/TD&gt;&lt;TD align="right"&gt;20311&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" height="17"&gt;992346&lt;/TD&gt;&lt;TD align="right"&gt;55236&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 18:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119966#M33037</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2012-11-07T18:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119967#M33038</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does this do what you want?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input stukey $ school $ fcode $;&lt;BR /&gt;cards;&lt;BR /&gt;992346 20311 D&lt;BR /&gt;992346 23659 C&lt;BR /&gt;992346 20311 B&lt;BR /&gt;992346 55236 A&lt;BR /&gt;992346 20311 D&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data=test out=test2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;BR /&gt;data enr dup;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set test2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if first.fcode then output enr;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else output dup;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 19:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119967#M33038</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-11-07T19:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119968#M33039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are a couple of ways to accomplish what you want.&amp;nbsp; Here is one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;input stukey $ school $ fcode $;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;992346 20311 D&lt;/P&gt;&lt;P&gt;992346 23659 C&lt;/P&gt;&lt;P&gt;992346 20311 B&lt;/P&gt;&lt;P&gt;992346 55236 A&lt;/P&gt;&lt;P&gt;992346 20311 D&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* if you want to keep the current order of the records&lt;/P&gt;&lt;P&gt;you will have to add a variable showing the order.&amp;nbsp; e.g.:*/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; recnum=_n_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*then you have to sort the file*/&lt;/P&gt;&lt;P&gt;proc sort data=test nodupkey;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*then sort the file back to the original order*/&lt;/P&gt;&lt;P&gt;proc sort data=test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by recnum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*then get rid of the extra field*/&lt;/P&gt;&lt;P&gt;data test (drop=recnum);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=test;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 19:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119968#M33039</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-07T19:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119969#M33040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want just one observation per combination of the three variables, does it matter if you take the first one, the last one, or a middle one?&amp;nbsp; If not, try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=test out=test2 NODUPKEY;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have to take the first one (and not the last or a middle one), try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data just_first;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if first.fcode;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But really, you should take ArtC's suggestion from earlier, and try to understand how these tools work.&amp;nbsp; After sorting, try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; by stukey school fcode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; first_stukey = first.stukey;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; last_stukey = last.stukey;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; first_school = first.school;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; last_school = last.school;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; first_fcode = first.fcode;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; last_fcode = last.fcode;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=temp (obs=50);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These will be important tools to know about in the long run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 19:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119969#M33040</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-11-07T19:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119970#M33041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It worked.&amp;nbsp; Thank you so much for your effort and time. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 21:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119970#M33041</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2012-11-07T21:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: If first statements Part II</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119971#M33042</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was able to get it to work.&amp;nbsp; Thank you so much for your time and I will definitely look further into ArtC's approach. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Nov 2012 21:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/If-first-statements-Part-II/m-p/119971#M33042</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2012-11-07T21:37:16Z</dc:date>
    </item>
  </channel>
</rss>

