<?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 Automate a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automate-a-Macro/m-p/305075#M65035</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I offset this below so that the &lt;STRONG&gt;start= &lt;/STRONG&gt;will always be the first month of the year &lt;STRONG&gt;(&lt;/STRONG&gt;this year it’s &lt;STRONG&gt;01jan2016&lt;/STRONG&gt; but next year I need it to say &lt;STRONG&gt;01jan2017 &lt;/STRONG&gt;and so on&lt;STRONG&gt;)&lt;/STRONG&gt; and then have the &lt;STRONG&gt;stop&lt;/STRONG&gt;= as the previous month? The idea is I want to automate this to prevent user error by keying in the incorrect month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; scants(start=&lt;STRONG&gt;01&lt;/STRONG&gt;jan2016,stop=01apr2016);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;%local i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=-%sysfunc(intck(month,&lt;STRONG&gt;"&amp;amp;start."d&lt;/STRONG&gt;,%sysfunc(today()))) %to -%sysfunc(intck(month,&lt;STRONG&gt;"&amp;amp;stop."d&lt;/STRONG&gt;,%sysfunc(today())));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let runmonth=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),yymmn6.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let month=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),monyy5.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; %let month2=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; %put &amp;amp;month2.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let startcomp = %sysfunc(intnx(month,"&amp;amp;month2"d,0,b),date9.); %put &amp;amp;startcomp.;&lt;/P&gt;
&lt;P&gt;%let endcomp = %sysfunc(intnx(month,"&amp;amp;month2"d,0,e),date9.); %put &amp;amp;endcomp.;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2016 13:17:59 GMT</pubDate>
    <dc:creator>anonymous_user</dc:creator>
    <dc:date>2016-10-17T13:17:59Z</dc:date>
    <item>
      <title>Automate a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-a-Macro/m-p/305075#M65035</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I offset this below so that the &lt;STRONG&gt;start= &lt;/STRONG&gt;will always be the first month of the year &lt;STRONG&gt;(&lt;/STRONG&gt;this year it’s &lt;STRONG&gt;01jan2016&lt;/STRONG&gt; but next year I need it to say &lt;STRONG&gt;01jan2017 &lt;/STRONG&gt;and so on&lt;STRONG&gt;)&lt;/STRONG&gt; and then have the &lt;STRONG&gt;stop&lt;/STRONG&gt;= as the previous month? The idea is I want to automate this to prevent user error by keying in the incorrect month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; scants(start=&lt;STRONG&gt;01&lt;/STRONG&gt;jan2016,stop=01apr2016);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;%local i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=-%sysfunc(intck(month,&lt;STRONG&gt;"&amp;amp;start."d&lt;/STRONG&gt;,%sysfunc(today()))) %to -%sysfunc(intck(month,&lt;STRONG&gt;"&amp;amp;stop."d&lt;/STRONG&gt;,%sysfunc(today())));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let runmonth=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),yymmn6.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let month=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),monyy5.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; %let month2=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;i.),date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; %put &amp;amp;month2.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let startcomp = %sysfunc(intnx(month,"&amp;amp;month2"d,0,b),date9.); %put &amp;amp;startcomp.;&lt;/P&gt;
&lt;P&gt;%let endcomp = %sysfunc(intnx(month,"&amp;amp;month2"d,0,e),date9.); %put &amp;amp;endcomp.;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-a-Macro/m-p/305075#M65035</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2016-10-17T13:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Automate a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automate-a-Macro/m-p/305082#M65038</link>
      <description>&lt;P&gt;Oh my, what an eyesore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For $DEITY's sake, just do your calculations in a data step and use call symput() at the end to store the results in macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
today = date();
lastmonth = intnx('month',today,-1,'begin');
yearstart = intnx('year',today,0,'begin');
call symput('stop',put(lastmonth,5.));
call symput('start',put(yearstart,5.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that it is not necessary to format the dates, the raw values can easily be used in comparisons with other date values.&lt;/P&gt;
&lt;P&gt;If you want to call a macro repeatedly, calculate (or read) the parameters in a data step and use call execute() to call the macro.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2016 13:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automate-a-Macro/m-p/305082#M65038</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-17T13:30:19Z</dc:date>
    </item>
  </channel>
</rss>

