<?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: Get the last record if the variable = a particular value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588600#M168238</link>
    <description>I want all A records regardless&lt;BR /&gt;I want the C or R records that occurred directly after the A record.  In my dataset, several R and C records show up.  I want to show just the one that occurred after the A record for counting puposes.  I want to count all A records and just the first C or R</description>
    <pubDate>Fri, 13 Sep 2019 17:26:43 GMT</pubDate>
    <dc:creator>Q1983</dc:creator>
    <dc:date>2019-09-13T17:26:43Z</dc:date>
    <item>
      <title>Get the last record if the variable = a particular value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588585#M168229</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mydate &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no $ code $ mydate &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1123 C 1jun2018&lt;/P&gt;
&lt;P&gt;1123 C 11jun2018&lt;/P&gt;
&lt;P&gt;1123 A 15jun2018&lt;/P&gt;
&lt;P&gt;1123 A 12jun2018&lt;/P&gt;
&lt;P&gt;1123 R 9jun2018&lt;/P&gt;
&lt;P&gt;1123 R 3jun2018&lt;/P&gt;
&lt;P&gt;1123 A 3May2018&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= have &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= have2; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ln_no &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;descending&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mydate;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I am attempting to do the following:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;The dataset reads from bottom up.&amp;nbsp; I want to show all instances of code = 'A' regardless.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I only want to show the first instance of a code = 'C' or code = 'R' that occurred after the 'A' code status.&amp;nbsp; So in this case I need to show rows 1,2,5,6 and 7.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Rows 3,4,5 would be eliminated.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;is there a way to do this within rows???&amp;nbsp; Essentially I do not want to read consecutive 'R' or 'C' rows unless an 'A' status appeared. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 16:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588585#M168229</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2019-09-13T16:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Get the last record if the variable = a particular value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588599#M168237</link>
      <description>&lt;P&gt;Would it be fair to say that you want to get the last record with code R or C that occured before a code A, and that code A record?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588599#M168237</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-13T17:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Get the last record if the variable = a particular value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588600#M168238</link>
      <description>I want all A records regardless&lt;BR /&gt;I want the C or R records that occurred directly after the A record.  In my dataset, several R and C records show up.  I want to show just the one that occurred after the A record for counting puposes.  I want to count all A records and just the first C or R</description>
      <pubDate>Fri, 13 Sep 2019 17:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588600#M168238</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2019-09-13T17:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get the last record if the variable = a particular value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588609#M168243</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data= have out= have2; by ln_no mydate;run;

data want(keep= ln_no code mydate);
   set have2;
   retain first_C first_R;
   if first.ln_no then do;
      first_C = 0;
      first_R = 0;
      end;
   if code eq 'A' then output;
   else if code eq 'C' and first_C eq 0 then do; 
      output;
      first_C = 1;
      end;
   else if code eq 'R' and first_R eq 0 then do;
      output;
      first_R = 1;
      end;
   by ln_no mydate;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588609#M168243</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2019-09-13T17:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Get the last record if the variable = a particular value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588617#M168247</link>
      <description>&lt;P&gt;Is this it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format mydate date9.;
input ln_no $ code $ mydate date9.;
datalines;
1123 C 1jun2018
1123 C 11jun2018
1123 A 15jun2018
1123 A 12jun2018
1123 R 9jun2018
1123 R 3jun2018
1123 A 3May2018
;

proc sort data= have out= have2; 
by ln_no mydate;
run;

data temp / view=temp;
set have;
grp + (code = "A");
run;

data want;
do until(last.grp);
	set temp; by grp;
	select (code);
		when ("A") output;
		when ("C", "R") do;
			if not found then output;
			found = 1;
			end;
		otherwise;
		end;
	end;
drop grp found;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs. 	mydate 	ln_no 	code
1 	01JUN2018 	1123 	C
2 	15JUN2018 	1123 	A
3 	12JUN2018 	1123 	A
4 	09JUN2018 	1123 	R
5 	03MAY2018 	1123 	A&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Sep 2019 18:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-the-last-record-if-the-variable-a-particular-value/m-p/588617#M168247</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-09-13T18:07:28Z</dc:date>
    </item>
  </channel>
</rss>

