<?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: How to take Max date in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596502#M76203</link>
    <description>&lt;P&gt;Do you mean this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
Input subj test $ result Date :yymmdd10.;
format date yymmdd10.;
lines;
101 DIA 56 2012-03-25
101 DIA 54 2012-03-28
101 SYS 105 2013-11-23
101 SYS 108 2013-10-10
101 SYS 110 2013-11-29
;
proc sql;
create table want as
select *, max((test='SYS')*date) as max format=yymmdd10.
from new
group by subj;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 15 Oct 2019 12:41:57 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-15T12:41:57Z</dc:date>
    <item>
      <title>How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596498#M76202</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;So I've data which contains of.&lt;BR /&gt;&lt;BR /&gt;Data new;&lt;BR /&gt;Input subj test $ result Date&lt;BR /&gt;Data lines;&lt;BR /&gt;101 DIA 56 2012-03-25&lt;BR /&gt;101 DIA 54 2012-03-28&lt;BR /&gt;101 SYS 105 2013-11-23&lt;BR /&gt;101 SYS 108 2013-10-10&lt;BR /&gt;101 SYS 110 2013-11-29&lt;BR /&gt;;&lt;BR /&gt;so I need the New variable "NEW" that contains only latest date of 'SYS' test only. Could you please tell me how to get that variable.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Oct 2019 12:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596498#M76202</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-10-15T12:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596502#M76203</link>
      <description>&lt;P&gt;Do you mean this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
Input subj test $ result Date :yymmdd10.;
format date yymmdd10.;
lines;
101 DIA 56 2012-03-25
101 DIA 54 2012-03-28
101 SYS 105 2013-11-23
101 SYS 108 2013-10-10
101 SYS 110 2013-11-29
;
proc sql;
create table want as
select *, max((test='SYS')*date) as max format=yymmdd10.
from new
group by subj;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Oct 2019 12:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596502#M76203</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-15T12:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596507#M76204</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;asked not sure if you want the whole column set to the max date for "SYS", or if you just want a macro variable with the value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following creates a new column using a data step alternative:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input subj
         test   $
         result
         date   yymmdd10.
   ;

   format date date9.;

   datalines;
101 DIA 56 2012-03-25
101 DIA 54 2012-03-28
101 SYS 105 2013-11-23
101 SYS 108 2013-10-10
101 SYS 110 2013-11-29
;

/* use double DOW loop */
data want;
   do until (last_check);
      set have end = last_check;
      if test eq 'SYS' then
         new = max(new,date);
   end;

   format new date9.;

   do until (last_obs);
      set have end = last_obs;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 13:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596507#M76204</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-10-15T13:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596817#M76217</link>
      <description>Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; !&lt;BR /&gt;I run the program which you gave. So the new column max contains the maximum date for all tests but I need only for test 'SYS' .&lt;BR /&gt;How do that one.</description>
      <pubDate>Wed, 16 Oct 2019 11:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596817#M76217</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-10-16T11:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596824#M76218</link>
      <description>&lt;P&gt;What value should be in the new column for the rows that do not have a test value of 'SYS'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should they be blank or have the same value as the date column or something else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 11:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596824#M76218</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-10-16T11:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596826#M76219</link>
      <description>Thank you for your quick response!!&lt;BR /&gt;&lt;BR /&gt;Yeah, they should be blank (The rows do not have test 'SYS')</description>
      <pubDate>Wed, 16 Oct 2019 11:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596826#M76219</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-10-16T11:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596829#M76220</link>
      <description>&lt;P&gt;I should have said missing, rather than blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code sets the value to missing, which for numeric values is '.' by default, but if you really want a blank then you can comment out the options statement at the top to change the default from '.' to '', but the value will still be considered as missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* change default numeric missing from '.' to '' */
*options missing = '';

/* use double DOW loop */
data want(drop = saved_new);
   do until (last_check);
      set have end = last_check;
      if test eq 'SYS' then
         new = max(new,date);
   end;

   format new date9.;
   saved_new = new;

   do until (last_obs);
      set have end = last_obs;

      if test ne 'SYS' then
         call missing(new);
      else
         new = saved_new;

      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 11:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596829#M76220</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-10-16T11:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596833#M76221</link>
      <description>Thank you so much for your assistance</description>
      <pubDate>Wed, 16 Oct 2019 11:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596833#M76221</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-10-16T11:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to take Max date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596845#M76222</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp; A simple tweak&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
Input subj test $ result Date :yymmdd10.;
format date yymmdd10.;
lines;
101 DIA 56 2012-03-25
101 DIA 54 2012-03-28
101 SYS 105 2013-11-23
101 SYS 108 2013-10-10
101 SYS 110 2013-11-29
;
proc sql;
create table want as
select *, ifn(test='SYS',max((test='SYS')*date),.) as max format=yymmdd10.
from new
group by subj;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2019 12:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-take-Max-date/m-p/596845#M76222</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-16T12:18:08Z</dc:date>
    </item>
  </channel>
</rss>

