<?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 date macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322520#M71353</link>
    <description>&lt;P&gt;I am still having trouble with date tokens. &amp;nbsp;I have a date global macro variable and I want to compute another one that is 45 days earlier. I have tried both assigning with and without quotes and using %LET and call symput. I am using SAS 9.4. What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET pulldate = 11/29/2016 ;&lt;BR /&gt;/*%LET pulldate = '11/29/2016' ; */&lt;/P&gt;&lt;P&gt;Try 1:&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;%global earlyTerm ;&lt;BR /&gt;call symputX('earlyTerm' , %sysfunc(input(&amp;amp;pulldate., mmddyy10.)-45)) ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Try 2:&lt;/P&gt;&lt;P&gt;%LET earlyTerm = %sysfunc(input(&amp;amp;pulldate., mmddyy10.)-45))&lt;/P&gt;&lt;P&gt;%put &amp;amp;earlyterm. ;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 22:23:05 GMT</pubDate>
    <dc:creator>CP2</dc:creator>
    <dc:date>2017-01-04T22:23:05Z</dc:date>
    <item>
      <title>date macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322520#M71353</link>
      <description>&lt;P&gt;I am still having trouble with date tokens. &amp;nbsp;I have a date global macro variable and I want to compute another one that is 45 days earlier. I have tried both assigning with and without quotes and using %LET and call symput. I am using SAS 9.4. What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET pulldate = 11/29/2016 ;&lt;BR /&gt;/*%LET pulldate = '11/29/2016' ; */&lt;/P&gt;&lt;P&gt;Try 1:&lt;/P&gt;&lt;P&gt;data _null_ ;&lt;/P&gt;&lt;P&gt;%global earlyTerm ;&lt;BR /&gt;call symputX('earlyTerm' , %sysfunc(input(&amp;amp;pulldate., mmddyy10.)-45)) ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Try 2:&lt;/P&gt;&lt;P&gt;%LET earlyTerm = %sysfunc(input(&amp;amp;pulldate., mmddyy10.)-45))&lt;/P&gt;&lt;P&gt;%put &amp;amp;earlyterm. ;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 22:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322520#M71353</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-01-04T22:23:05Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322527#M71357</link>
      <description>&lt;P&gt;You're close. You're mixing data step and macro logic. I recommend data step if you're not familiar with macro functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changes;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;remove %global&lt;/LI&gt;
&lt;LI&gt;Add &amp;nbsp;third parameter of CALL SYMPUTX to specify global macro variable&lt;/LI&gt;
&lt;LI&gt;Remove %sysfunc as not required&lt;/LI&gt;
&lt;LI&gt;Add quotation marks around variable&lt;/LI&gt;
&lt;LI&gt;Added version with a formatted date&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET pulldate = 11/29/2016 ;
data _null_ ;
call symputX('earlyTerm' , input("&amp;amp;pulldate.", mmddyy10.)-45, 'g') ;
call symputX('earlyTermDate' , put(input("&amp;amp;pulldate.", mmddyy10.)-45, date9.), 'g') ;
run;

%put &amp;amp;earlyTerm;
%put &amp;amp;earlyTermDate;&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;</description>
      <pubDate>Wed, 04 Jan 2017 22:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322527#M71357</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-04T22:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322535#M71359</link>
      <description>&lt;P&gt;You could just use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let pulldate = %sysevalf('29nov2016'd);&lt;BR /&gt;%let earlyTerm =%sysevalf(&amp;amp;pulldate.-45);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 22:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322535#M71359</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-01-04T22:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: date macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322609#M71393</link>
      <description>&lt;P&gt;You've got close on your second try.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you really have to use the &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;MM//DD/YYYY&lt;/STRONG&gt;&lt;/FONT&gt; format for the &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;PULLDATE&lt;/FONT&gt; &lt;/STRONG&gt;var, this will do the trick:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* set;
%let pulldate = 11/29/2016 ;
%let earlyTerm = %eval(%sysfunc(inputn(&amp;amp;pulldate,mmddyy10.))-45);

* show;
%put &amp;amp;earlyterm.;
%put %sysfunc(putn(&amp;amp;earlyterm,mmddyy10.));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;inputn/inputc&lt;/STRONG&gt;&lt;/FONT&gt; or &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;putn/putc&lt;/FONT&gt;&lt;/STRONG&gt; with &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%sysfunc&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some functions (like &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input/put&lt;/STRONG&gt;&lt;/FONT&gt;)&amp;nbsp;won't work with &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;%sysfunc&lt;/FONT&gt;&lt;/STRONG&gt;, more info here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1o13d7wb2zfcnn19s5ssl2zdxvi.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1o13d7wb2zfcnn19s5ssl2zdxvi.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Also, to perform the calculation (-45) you need to force the expression for evaluation, hence the &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;%eval&lt;/FONT&gt; &lt;/STRONG&gt;macro functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More on &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;%eval&lt;/STRONG&gt;&lt;/FONT&gt;: &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n07pr39df9k7m3n1w3x1q09iewta.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#n07pr39df9k7m3n1w3x1q09iewta.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;%sysevalf&lt;/FONT&gt;&lt;/STRONG&gt; will do the trick, but is intended to be used with floating point arithmetic, which is not the case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More on &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;%sysevalf&lt;/FONT&gt;&lt;/STRONG&gt;: &lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1d9ypna2tpt16n1xam57kuffcpt.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1d9ypna2tpt16n1xam57kuffcpt.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 08:38:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-macro-variables/m-p/322609#M71393</guid>
      <dc:creator>Daniel-Santos</dc:creator>
      <dc:date>2017-01-05T08:38:09Z</dc:date>
    </item>
  </channel>
</rss>

