<?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 %Let macro variable be max date in dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371356#M88712</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to make a macro variable that is the maximum date of the variable (datevar) in my dataset (mydata). Something along the lines of the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let max_dt = max(work.&lt;SPAN&gt;mydata&lt;/SPAN&gt;.datevar);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any recommendation would be much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;daszlosek&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2017 15:54:42 GMT</pubDate>
    <dc:creator>daszlosek</dc:creator>
    <dc:date>2017-06-28T15:54:42Z</dc:date>
    <item>
      <title>%Let macro variable be max date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371356#M88712</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to make a macro variable that is the maximum date of the variable (datevar) in my dataset (mydata). Something along the lines of the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let max_dt = max(work.&lt;SPAN&gt;mydata&lt;/SPAN&gt;.datevar);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any recommendation would be much appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;daszlosek&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 15:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371356#M88712</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-06-28T15:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: %Let macro variable be max date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371366#M88714</link>
      <description>&lt;P&gt;Use PROC SQL to find the max and put it into the macro variable.&lt;/P&gt;
&lt;P&gt;Depending on how you use it might want to format the value in different ways.&lt;/P&gt;
&lt;P&gt;This should get a number that you can use to compare to other DATE variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select max(datevar)
  into :max_dt trimmed
  from mydata
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could use something like this to get a string that you could use building a filename or title statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select max(datevar) format=yymmddn8.
  into :max_dt
  from mydata
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could generate the value in the form of a date literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select cats(quote(put(max(datevar),date9.)),'d')
  into :max_dt
  from mydata
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 16:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371366#M88714</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-28T16:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: %Let macro variable be max date in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371381#M88717</link>
      <description>&lt;P&gt;Worked like a charm! Have never used colons before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank&amp;nbsp;you!&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 17:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Let-macro-variable-be-max-date-in-dataset/m-p/371381#M88717</guid>
      <dc:creator>daszlosek</dc:creator>
      <dc:date>2017-06-28T17:27:53Z</dc:date>
    </item>
  </channel>
</rss>

