<?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: latest nonmissing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673760#M202741</link>
    <description>&lt;P&gt;Sorry i have the soultion you gave worked very well, i was trying the same will keeping all the observations and getting the output. Sorry for the confusion.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jul 2020 15:39:14 GMT</pubDate>
    <dc:creator>helpmedoubts</dc:creator>
    <dc:date>2020-07-31T15:39:14Z</dc:date>
    <item>
      <title>get the last record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673618#M202687</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input id test$ visit$ vsdate$ trtdate$ results;&lt;BR /&gt;datalines;&lt;BR /&gt;101 Weight Trt1 10jan2020 27Jan2020 22&lt;BR /&gt;101 Weight Trt2 22jan2020 27Jan2020 .&lt;BR /&gt;101 Weight Trt3 23jan2020 27Jan2020 23&lt;BR /&gt;101 Weight Trt4 27jan2020 27Jan2020 11&lt;BR /&gt;101 Weight Trt5 28jan2020 27Jan2020 98.5&lt;BR /&gt;101 Weight Trt6 15feb2020 27Jan2020 131&lt;BR /&gt;102 Weight Trt1 10jan2020 11Feb2020 261&lt;BR /&gt;102 Weight Trt2 22jan2020 11Feb2020 10&lt;BR /&gt;102 Weight Trt3 23jan2020 11Feb2020 45.345&lt;BR /&gt;102 Weight Trt4 15feb2020 11Feb2020 33&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;i have this data. Now i need to create a new variable baseline flag with value Y based on these conditions&lt;/P&gt;&lt;P&gt;1. vsdate should be le trtdate&lt;/P&gt;&lt;P&gt;2. results not missing&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;3. for latest visit&amp;nbsp; baseline flag should be Y&lt;/P&gt;&lt;P&gt;output should be liike this:&lt;/P&gt;&lt;P&gt;101 Weight Trt1 10jan2020 27Jan2020 22&lt;BR /&gt;101 Weight Trt3 23jan2020 27Jan2020 23&lt;BR /&gt;101 Weight Trt4 27jan2020 27Jan2020 11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&lt;BR /&gt;102 Weight Trt1 10jan2020 11Feb2020 261&lt;BR /&gt;102 Weight Trt2 22jan2020 11Feb2020 10&lt;BR /&gt;102 Weight Trt3 23jan2020 11Feb2020 45.345 &amp;nbsp; &amp;nbsp;&amp;nbsp; Y&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 12:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673618#M202687</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-07-31T12:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673621#M202689</link>
      <description>&lt;P&gt;Why are you reading the dates as char type variables? why not as sas numeric dates?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id test $ visit $ vsdate date9. trtdate date9. results;
datalines;
101 Weight Trt1 10jan2020 27Jan2020 22
101 Weight Trt2 22jan2020 27Jan2020 .
101 Weight Trt3 23jan2020 27Jan2020 23
101 Weight Trt4 27jan2020 27Jan2020 11
101 Weight Trt5 28jan2020 27Jan2020 98.5
101 Weight Trt6 15feb2020 27Jan2020 131
102 Weight Trt1 10jan2020 11Feb2020 261
102 Weight Trt2 22jan2020 11Feb2020 10
102 Weight Trt3 23jan2020 11Feb2020 45.345
102 Weight Trt4 15feb2020 11Feb2020 33
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;alternatively you need a second step to convert the dates into sas numeric dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
 set have(rename=(vsdate=dt1 trtdate=dt2));
       vsdate = input(dt1, date9.);
       trtdate = input(dt2,date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;having numeric dates it will be easy to do what you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have(where=(vsdate &amp;lt; trtdate and results ne .))  /* or data=new */
               out=temp;
       by ID visit  vsdate;
run;
data want;
 set temp;
       by ID visit;
           if last.visit then flag ="Y";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember that a numeric sas date is counting days since 01Jan1960 as 0;&lt;/P&gt;
&lt;P&gt;to clarify it run next code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    dt = '01JAN1960'd;
    td = today();
   put dt=  td=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Jul 2020 13:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673621#M202689</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-31T13:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673692#M202714</link>
      <description>&lt;P&gt;Thank you! its working. but I want to keep all the records in the output , if we use where option only particular set of observations are being selected. can you please help me with that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 12:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673692#M202714</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-07-31T12:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673697#M202716</link>
      <description>&lt;P&gt;And is there any alternative solution for this? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 12:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673697#M202716</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-07-31T12:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673704#M202720</link>
      <description>&lt;P&gt;You asked to remove those observation with vsdate &amp;gt;trtdate, as in your wanted result:&lt;/P&gt;
&lt;PRE&gt;output should be liike this:

101 Weight Trt1 10jan2020 27Jan2020 22
101 Weight Trt3 23jan2020 27Jan2020 23
101 Weight Trt4 27jan2020 27Jan2020 11            Y
102 Weight Trt1 10jan2020 11Feb2020 261
102 Weight Trt2 22jan2020 11Feb2020 10
102 Weight Trt3 23jan2020 11Feb2020 45.345      Y&lt;/PRE&gt;
&lt;P&gt;thats what the&amp;nbsp; where statement do.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 13:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673704#M202720</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-07-31T13:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673760#M202741</link>
      <description>&lt;P&gt;Sorry i have the soultion you gave worked very well, i was trying the same will keeping all the observations and getting the output. Sorry for the confusion.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 15:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673760#M202741</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-07-31T15:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: latest nonmissing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673783#M202752</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can possibly "put back" observations removed, by joining the original table&amp;nbsp; (have) with processed one (want) into want1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;&lt;BR /&gt;create table want1 as
select a.*, b.baseline_flag 
 from have a
  left join want b
  on 	a.Id = b.id and 
		a.vsdate = b.vsdate and
		a.trtdate = b.trtdate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sql code which may help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select * , case 
			when vsdate  eq max(vsdate) 
				 then 'Y'
			else ''
		  end as baseline_flag 
		from have 
			where vsdate le trtdate 	 and	
			      vsdate  is not missing and
				  trtdate is not missing
			group by id;		
quit; 
	&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 16:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-the-last-record/m-p/673783#M202752</guid>
      <dc:creator>tocilj</dc:creator>
      <dc:date>2020-07-31T16:22:11Z</dc:date>
    </item>
  </channel>
</rss>

