<?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 setting macro dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9283#M452</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a logic problem and an issue with creating a macro that will take a previous month end date from a specified date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;if i have a date at any point before the&amp;nbsp; month end i'l like to create a USAGE_TIMESTAMP variable of the previous month end.&lt;/P&gt;&lt;P&gt;otherwise if i have a date at the month end i'd like the USAGE_TIMESTAMP to be at the current month end.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if the above is possible to automate but an example would be as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Middle of the month example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET DATE='15NOV2011'D;&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=2011NOV15;&lt;/P&gt;&lt;P&gt;%LET USAGE_TIMESTAMP =2011OCT31&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Month end example:&lt;/P&gt;&lt;P&gt;%LET DATE='30NOV2011'D;&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=2011NOV30;&lt;/P&gt;&lt;P&gt;%LET USAGE_TIMESTAMP =2011NOV30&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i've tried the following for USAGE_TIMESTAMP, it gives me the right date, but i tried using it in a data step (data A.FILE_&amp;amp;USAGE_TIMESTAMP) and i get an error because it is outputting the formula as a text rather than the "2011OCT31": &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %LET USAGE_TIMESTAMP = INTNX('MONTH',&amp;amp;DATE,-1,'END') ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Feb 2012 19:04:17 GMT</pubDate>
    <dc:creator>Danglytics</dc:creator>
    <dc:date>2012-02-21T19:04:17Z</dc:date>
    <item>
      <title>setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9283#M452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a logic problem and an issue with creating a macro that will take a previous month end date from a specified date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;if i have a date at any point before the&amp;nbsp; month end i'l like to create a USAGE_TIMESTAMP variable of the previous month end.&lt;/P&gt;&lt;P&gt;otherwise if i have a date at the month end i'd like the USAGE_TIMESTAMP to be at the current month end.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if the above is possible to automate but an example would be as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Middle of the month example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET DATE='15NOV2011'D;&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=2011NOV15;&lt;/P&gt;&lt;P&gt;%LET USAGE_TIMESTAMP =2011OCT31&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Month end example:&lt;/P&gt;&lt;P&gt;%LET DATE='30NOV2011'D;&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=2011NOV30;&lt;/P&gt;&lt;P&gt;%LET USAGE_TIMESTAMP =2011NOV30&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i've tried the following for USAGE_TIMESTAMP, it gives me the right date, but i tried using it in a data step (data A.FILE_&amp;amp;USAGE_TIMESTAMP) and i get an error because it is outputting the formula as a text rather than the "2011OCT31": &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %LET USAGE_TIMESTAMP = INTNX('MONTH',&amp;amp;DATE,-1,'END') ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 19:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9283#M452</guid>
      <dc:creator>Danglytics</dc:creator>
      <dc:date>2012-02-21T19:04:17Z</dc:date>
    </item>
    <item>
      <title>setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9284#M453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you want to do something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET DATE=%sysevalf('30NOV2011'd);&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=%sysevalf('30NOV2011'd);&lt;/P&gt;&lt;P&gt;%LET USAGE_TIMESTAMP = %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,end));&lt;/P&gt;&lt;P&gt;%put &amp;amp;usage_timestamp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 20:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9284#M453</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-21T20:12:13Z</dc:date>
    </item>
    <item>
      <title>setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9285#M454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple of issues.&lt;/P&gt;&lt;P&gt;1) I am not sure there is a predefined format that reverses the year and day positions of the DATE9 format. &lt;/P&gt;&lt;P&gt;2) To call a function in macro code you need to use %SYSFUNC().&amp;nbsp; Also the text fields (like MONTH in your example) do not require the quotes in macro code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let date='15NOV2011'd;&lt;/P&gt;&lt;P&gt;%let timestamp=%sysfunc(putn(&amp;amp;date,yymmddn8.));&lt;/P&gt;&lt;P&gt;%let usage_timestamp=%sysfunc(intnx(MONTH,&amp;amp;date,-1,END),yymmddn8.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 20:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9285#M454</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-02-21T20:30:22Z</dc:date>
    </item>
    <item>
      <title>setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9286#M455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could increment the current date by one in a data step, that would always put you to the previous month end.&lt;/P&gt;&lt;P&gt;%LET TIMESTAMP=29NOV2011; &lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SASDate=INPUT("&amp;amp;TIMESTAMP",date9.)+1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SASDate1=INTNX('MONTH',SASDate,-1,'END');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CALL SYMPUT("usage_timestamp",PUT(SASDate1, date9.)); &lt;BR /&gt;RUN; &lt;BR /&gt;DATA FILE_&amp;amp;usage_timestamp; &lt;BR /&gt;PreviousMonthEnd="&amp;amp;usage_timestamp"; &lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;﻿&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 21:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9286#M455</guid>
      <dc:creator>TG_WPAFB</dc:creator>
      <dc:date>2012-02-21T21:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9287#M456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this macro produces the effect you desire:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;%macro timestamp(Date);
&amp;nbsp;&amp;nbsp; %LET DATE=%sysevalf("&amp;amp;date"d);
&amp;nbsp;&amp;nbsp; %if %sysfunc(month(&amp;amp;date)) =%sysfunc(month(%eval(&amp;amp;date+1))) %then 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %LET Stamp= %sysfunc(INTNX(MONTH,&amp;amp;DATE,-1,end));
&amp;nbsp;&amp;nbsp; %else %let Stamp=&amp;amp;Date;
&amp;nbsp;&amp;nbsp; %sysfunc(cats(%sysfunc(PUTN(&amp;amp;Stamp,YYMON7.)),%sysfunc(day(&amp;amp;Stamp))));
%mend;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This macro utility can be used like a macro function, that is, it can be used in-line with other SAS code to return the text value for the usage_timestamp (YYYYMMMDD).&amp;nbsp; After compling the macro, try it out with various values - perhaps using code similar to this: &lt;/P&gt;&lt;PRE&gt; 
%put NOTE: USAGE_TIMESTAMP = %timestamp(20NOV2011);
%put NOTE: USAGE_TIMESTAMP = %timestamp(30NOV2011);
%put NOTE: USAGE_TIMESTAMP = %timestamp(20DEC2011);
%put NOTE: USAGE_TIMESTAMP = %timestamp(31DEC2011);
%put NOTE: USAGE_TIMESTAMP = %timestamp(02JAN2012);
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 23:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9287#M456</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2012-02-21T23:06:32Z</dc:date>
    </item>
    <item>
      <title>setting macro dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9288#M457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi DanglyticS, Try this out:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*------------ START SAS CODE EXAMPLE ------------- */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA _NULL_;&lt;/P&gt;&lt;P&gt;DT = TODAY();&lt;/P&gt;&lt;P&gt;TIMESTAMP = DT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF DT = INTNX('MONTH',DT,1)-1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; THEN DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USAGE_TIMESTAMP = DT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ELSE DO;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; USAGE_TIMESTAMP = INTNX('MONTH',DT,0)-1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PUT USAGE_TIMESTAMP=;&amp;nbsp; /* PRINT DATE IN LOG TO MAKE SURE IT IS CORRECT FORMAT */&lt;/P&gt;&lt;P&gt;FORMAT USAGE_TIMESTAMP DATE9.;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*-------------------- END SAS CODE EXAMPLE ---------------- */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps you out.&lt;/P&gt;&lt;P&gt;Jon S.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 23:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/setting-macro-dates/m-p/9288#M457</guid>
      <dc:creator>JonS_</dc:creator>
      <dc:date>2012-02-21T23:18:37Z</dc:date>
    </item>
  </channel>
</rss>

