<?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: today() Custom Replacement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599863#M173251</link>
    <description>&lt;P&gt;This is, I think, the right way to establish the value for macrovar DATE2.&amp;nbsp; The only downside I see is that it is a numeric value (21184 in the case of year=2019, month=3).&amp;nbsp; It will work in any date filtering (i.e. &amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; WHERE MYDATE &amp;gt;= &amp;amp;DATE2&lt;/STRONG&gt;&lt;/FONT&gt;), but of course is not a user-friendly way to understand what date is being represented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest considering the format option in the SYSFUNC function (the ",date9." portion below):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date2b= %sysfunc(intnx(month, %sysfunc(mdy(&amp;amp;monthuse, 1, &amp;amp;yearuse)),-15,end),date9.);
%put &amp;amp;=date2b;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then DATE2B will have the value 31DEC2017.&amp;nbsp; Much easier for the user to read.&amp;nbsp; And not much harder to use as a date filter.&amp;nbsp; Just let SAS know it is a date literal, as in &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;WHERE MYDATE &amp;gt;="&amp;amp;date2b"d&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2019 16:32:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2019-10-28T16:32:32Z</dc:date>
    <item>
      <title>today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599853#M173241</link>
      <description>&lt;P&gt;I have the following in a macro:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let date2 = %sysfunc(intnx(month,%sysfunc(today()),-15,end));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to replace the today() with a custom field for a date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let yearuse = 2019;&lt;/P&gt;&lt;P&gt;%let monthuse = 3;&lt;/P&gt;&lt;P&gt;%let date2 = %sysfunc(intnx(month,%sysfunc(today()),-15,end));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would I replace the today() above with?&amp;nbsp; That is, I want 15 months back from the 2019 month 3 above it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 17:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599853#M173241</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2019-10-28T17:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599856#M173244</link>
      <description>&lt;P&gt;Assuming you correct these invalid statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%yearuse = 2019;&lt;/P&gt;
&lt;P&gt;%monthuse = 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;there would be a few ways.&amp;nbsp; Here's one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date2 = %sysfunc(intnx(month, %sysfunc(mdy(&amp;amp;monthuse, 1, &amp;amp;yearuse)),-15,end));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 16:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599856#M173244</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-28T16:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599858#M173246</link>
      <description>Replace today() with mdy(&amp;amp;monthuse,1,&amp;amp;yearuse)</description>
      <pubDate>Mon, 28 Oct 2019 16:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599858#M173246</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-10-28T16:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599863#M173251</link>
      <description>&lt;P&gt;This is, I think, the right way to establish the value for macrovar DATE2.&amp;nbsp; The only downside I see is that it is a numeric value (21184 in the case of year=2019, month=3).&amp;nbsp; It will work in any date filtering (i.e. &amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt; WHERE MYDATE &amp;gt;= &amp;amp;DATE2&lt;/STRONG&gt;&lt;/FONT&gt;), but of course is not a user-friendly way to understand what date is being represented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest considering the format option in the SYSFUNC function (the ",date9." portion below):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date2b= %sysfunc(intnx(month, %sysfunc(mdy(&amp;amp;monthuse, 1, &amp;amp;yearuse)),-15,end),date9.);
%put &amp;amp;=date2b;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then DATE2B will have the value 31DEC2017.&amp;nbsp; Much easier for the user to read.&amp;nbsp; And not much harder to use as a date filter.&amp;nbsp; Just let SAS know it is a date literal, as in &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;WHERE MYDATE &amp;gt;="&amp;amp;date2b"d&lt;/STRONG&gt;&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 16:32:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599863#M173251</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-28T16:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599865#M173252</link>
      <description>&lt;P&gt;You can't use your numeric month in a date literal.&amp;nbsp; You could use it in the MDY() function. You could use the first day of the year in the date in the date literal and use the month number to change the number of months you need to offset by.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yearuse = 2019;
%let monthuse = 10;

%let date1 = %sysfunc(intnx(month,%sysfunc(today()),-15,end));
%let date2 = %sysfunc(intnx(month,%sysfunc(mdy(&amp;amp;monthuse,1,&amp;amp;yearuse)),-15,end));
%let date3 = %sysfunc(intnx(month,"01JAN&amp;amp;yearuse"d,&amp;amp;monthuse-1-15,end));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;8     %put &amp;amp;=date1 &amp;amp;=date2 &amp;amp;=date3 ;
DATE1=21396 DATE2=21396 DATE3=21396
9     %put %sysfunc(putn(&amp;amp;date1,date9.));
31JUL2018
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 16:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599865#M173252</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-28T16:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: today() Custom Replacement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599892#M173267</link>
      <description>thanks!</description>
      <pubDate>Mon, 28 Oct 2019 18:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/today-Custom-Replacement/m-p/599892#M173267</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2019-10-28T18:15:33Z</dc:date>
    </item>
  </channel>
</rss>

