<?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: Date variables based on todays date for %let statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671385#M201611</link>
    <description>&lt;P&gt;Inside a macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=%sysfunc(today()); 
%if %sysfunc(day(&amp;amp;date))&amp;lt;16 %then %let enddate=%sysfunc(intnx(month,&amp;amp;date,-1,e));
%else %let enddate=%eval(%sysfunc(intnx(month,&amp;amp;date,0,b))+14);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jul 2020 14:10:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-07-22T14:10:43Z</dc:date>
    <item>
      <title>Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671382#M201610</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to set a &amp;amp;start_date and &amp;amp;end_date based on todays date.&amp;nbsp; If the day of the month is after the 16th id like the end_date to be the 15th of current month.&amp;nbsp; If the day of the month is before the 16th, id like the end_date to be the end of the prior month.&amp;nbsp; Hope that makes sense.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 13:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671382#M201610</guid>
      <dc:creator>wadar</dc:creator>
      <dc:date>2020-07-22T13:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671385#M201611</link>
      <description>&lt;P&gt;Inside a macro&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date=%sysfunc(today()); 
%if %sysfunc(day(&amp;amp;date))&amp;lt;16 %then %let enddate=%sysfunc(intnx(month,&amp;amp;date,-1,e));
%else %let enddate=%eval(%sysfunc(intnx(month,&amp;amp;date,0,b))+14);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671385#M201611</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-22T14:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671389#M201612</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
if day(today()) &amp;lt; 16 call symputx('end_date',intnx('month',today(),-1,'END'));
else call symputx('end_date',intnx('month',today(),0,'END'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671389#M201612</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-22T14:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671394#M201615</link>
      <description>&lt;P&gt;What if day of the month EQUALS 16 ?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671394#M201615</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-22T14:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671405#M201617</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What if day of the month EQUALS 16 ?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;An excellent question. But hopefully the OP can make the modifications to the above code to handle this issue.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671405#M201617</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-22T14:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671410#M201620</link>
      <description>&lt;P&gt;You are asking how to compute the end of either the prior semimonth or month depending on day in month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro end_date_test;

  %do today = %sysevalf("01JUL2020"D) %to %sysevalf("31JUL2020"D);

    %if %sysfunc(day(&amp;amp;today)) &amp;gt;= 16 %then %do;
      %let end_date = %sysfunc(intnx(semimonth2.2, &amp;amp;today, -1, E));
    %end;
    %else %do;
      %let end_date = %sysfunc(intnx(month, &amp;amp;today, -1, E));  
    %end;

    %put today=%sysfunc(putn(&amp;amp;today,date9.)) end_date=%sysfunc(putn(&amp;amp;end_date,date9.));

  %end;

%mend;

%end_date_test;&lt;/PRE&gt;
&lt;P&gt;The log should convince you the end_date computation meets your business rules&lt;/P&gt;
&lt;PRE&gt;today=01JUL2020 end_date=30JUN2020
today=02JUL2020 end_date=30JUN2020
today=03JUL2020 end_date=30JUN2020
today=04JUL2020 end_date=30JUN2020
today=05JUL2020 end_date=30JUN2020
today=06JUL2020 end_date=30JUN2020
today=07JUL2020 end_date=30JUN2020
today=08JUL2020 end_date=30JUN2020
today=09JUL2020 end_date=30JUN2020
today=10JUL2020 end_date=30JUN2020
today=11JUL2020 end_date=30JUN2020
today=12JUL2020 end_date=30JUN2020
today=13JUL2020 end_date=30JUN2020
today=14JUL2020 end_date=30JUN2020
today=15JUL2020 end_date=30JUN2020
today=16JUL2020 end_date=15JUL2020
today=17JUL2020 end_date=15JUL2020
today=18JUL2020 end_date=15JUL2020
today=19JUL2020 end_date=15JUL2020
today=20JUL2020 end_date=15JUL2020
today=21JUL2020 end_date=15JUL2020
today=22JUL2020 end_date=15JUL2020
today=23JUL2020 end_date=15JUL2020
today=24JUL2020 end_date=15JUL2020
today=25JUL2020 end_date=15JUL2020
today=26JUL2020 end_date=15JUL2020
today=27JUL2020 end_date=15JUL2020
today=28JUL2020 end_date=15JUL2020
today=29JUL2020 end_date=15JUL2020
today=30JUL2020 end_date=15JUL2020
today=31JUL2020 end_date=15JUL2020
&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671410#M201620</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-22T14:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671412#M201621</link>
      <description>&lt;P&gt;Interesting, I knew SEMIMONTH existed but have never used it. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apparently, in February, the SEMIMONTH is always the 15th, leap year or not.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671412#M201621</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-22T14:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671415#M201624</link>
      <description>this looks like exactly what I need. so if I just want it to incorporate this logic for todays date, can I just change&lt;BR /&gt;%do today =&lt;BR /&gt;%sysevalf("01JUL2020"D) %to %sysevalf("31JUL2020"D) to today()?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jul 2020 14:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671415#M201624</guid>
      <dc:creator>wadar</dc:creator>
      <dc:date>2020-07-22T14:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Date variables based on todays date for %let statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671838#M201804</link>
      <description>&lt;P&gt;Open code &lt;CODE&gt;%if %then %do&lt;/CODE&gt; blocks is a new feature in newer SAS versions, so extricate the assignment logic from the testing macro and use it open code.&amp;nbsp; Directly assign the &lt;CODE&gt;today&lt;/CODE&gt; macro variable the result of the &lt;CODE&gt;TODAY()&lt;/CODE&gt; function.&amp;nbsp; I use &lt;CODE&gt;today&lt;/CODE&gt; macro variable because the concept/value of today is used in three places in order to properly assign the &lt;CODE&gt;end_date&lt;/CODE&gt; its needed value.&lt;/P&gt;
&lt;PRE&gt;%let today = %sysfunc(TODAY());

%if %sysfunc(day(&amp;amp;today)) &amp;gt;= 16 %then %do;
  %let end_date = %sysfunc(intnx(semimonth2.2, &amp;amp;today, -1, E));
%end;
%else %do;
  %let end_date = %sysfunc(intnx(month, &amp;amp;today, -1, E));  
%end;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 14:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-variables-based-on-todays-date-for-let-statement/m-p/671838#M201804</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-07-23T14:46:57Z</dc:date>
    </item>
  </channel>
</rss>

