<?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: Multiple if last observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699990#M214166</link>
    <description>&lt;P&gt;It is not clear to me what you want.&lt;/P&gt;
&lt;P&gt;Try each of next IF statements:&lt;/P&gt;
&lt;P&gt;1) if last type;&lt;/P&gt;
&lt;P&gt;2) if last make;&lt;/P&gt;
&lt;P&gt;3) if last.type then putlog type=;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if last.make then putlog make=;&lt;/P&gt;
&lt;P&gt;4) if last.make or last.type;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 21:03:51 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-11-18T21:03:51Z</dc:date>
    <item>
      <title>Multiple if last observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699989#M214165</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;create table cars2 as&lt;BR /&gt;select make, type&lt;BR /&gt;from sashelp.cars&lt;BR /&gt;where make in ('Acura','Audi')&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;data cars3;&lt;BR /&gt;set cars2;&lt;BR /&gt;by make type;&lt;BR /&gt;if last.make and last.type;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The query gives the last make and type.&amp;nbsp; I want to show the last make and type in each category.&amp;nbsp; For example&lt;/P&gt;
&lt;P&gt;Make&amp;nbsp; &amp;nbsp; &amp;nbsp;Type&lt;/P&gt;
&lt;P&gt;Accura&amp;nbsp; &amp;nbsp;Sedan&lt;/P&gt;
&lt;P&gt;Accura&amp;nbsp; &amp;nbsp;Sports&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same scenario for Audi.&amp;nbsp; Instead I am getting the last observation period.&amp;nbsp; Is there a way to address in the proc sql statement or must it be done in the datastep?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 20:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699989#M214165</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2020-11-18T20:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple if last observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699990#M214166</link>
      <description>&lt;P&gt;It is not clear to me what you want.&lt;/P&gt;
&lt;P&gt;Try each of next IF statements:&lt;/P&gt;
&lt;P&gt;1) if last type;&lt;/P&gt;
&lt;P&gt;2) if last make;&lt;/P&gt;
&lt;P&gt;3) if last.type then putlog type=;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if last.make then putlog make=;&lt;/P&gt;
&lt;P&gt;4) if last.make or last.type;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699990#M214166</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-18T21:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple if last observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699992#M214168</link>
      <description>&lt;P&gt;This logic is not clear to me. Why do you want two observations for&amp;nbsp;&lt;SPAN&gt;Accura? If you want to show the last make &lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;type for each category, then what is your overall category?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699992#M214168</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-18T21:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple if last observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699993#M214169</link>
      <description>&lt;P&gt;If you want the last of each type for all of the makes then you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if last.type;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=sashelp.cars
   out=work.cars;
   by make type;
run;

data want;
   set work.cars (keep=make type);
   by make type;
   if last.type;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/699993#M214169</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-18T21:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple if last observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/700008#M214178</link>
      <description>&lt;P&gt;It is not clear what you mean by &lt;EM&gt;category&lt;/EM&gt;. Maybe you want this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cars2;
set sashelp.cars;
where make in ('Acura','Audi');
by make type notsorted;
if last.type;
/* keep make type; */
run;

proc print data=cars2 noobs; var make type; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 90px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51814iB7E964F2EFDAD4D5/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 21:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-if-last-observations/m-p/700008#M214178</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-11-18T21:56:10Z</dc:date>
    </item>
  </channel>
</rss>

