<?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: Macro Code Explanation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/332108#M74715</link>
    <description>&lt;P&gt;The purpose of this code is to make me rapidly hit the delete key. &amp;nbsp;It does virtually nothing except sit there as a mass of obfuscated code sucking up valuable programming hours.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2017 09:52:29 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-02-13T09:52:29Z</dc:date>
    <item>
      <title>Macro Code Explanation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331977#M74683</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Can someone please help me interpret what below sas code is doing.Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let start_dt1=%sysfunc(inputn(%SYSFUNC(INTNX(MONTH, &amp;amp;RUN_DATE.,%EVAL(-12*&amp;amp;PERIODS.-&amp;amp;RUNOUT.),B),yymmdd8.), yymmdd8.), date9.);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro my_function();&lt;BR /&gt;%global start_dt;&lt;/P&gt;
&lt;P&gt;%if %sysevalf(&amp;amp;ENRLMNTDY. = 1) %then&lt;BR /&gt;%do;&lt;BR /&gt;%let start_dt = &amp;amp;start_dt1.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %sysevalf(&amp;amp;ENRLMNTDY. = 15) %then&lt;BR /&gt;%do;&lt;BR /&gt;%let start_dt = %SYSFUNC(INTNX(DAY,"&amp;amp;start_dt1."d,14),DATE9.);&lt;BR /&gt;%end;&lt;BR /&gt;%else %if %sysevalf(&amp;amp;ENRLMNTDY. = "Last") %then&lt;BR /&gt;%do;&lt;BR /&gt;%let start_dt = %sysfunc(inputn(%SYSFUNC(INTNX(MONTH, &amp;amp;RUN_DATE.,%EVAL(-12*&amp;amp;PERIODS.-&amp;amp;RUNOUT.),E),yymmdd8.), yymmdd8.), date9.);&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;%mend my_function;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%my_function();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let end_dt=%sysfunc(inputn(%SYSFUNC(INTNX(MONTH, &amp;amp;RUN_DATE.,%EVAL(-1-&amp;amp;RUNOUT.),E),yymmdd8.), yymmdd8.), date9.);&lt;BR /&gt;%put &amp;amp;start_dt. &amp;amp;end_dt.;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 20:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331977#M74683</guid>
      <dc:creator>srdhoble</dc:creator>
      <dc:date>2017-02-12T20:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Code Explanation help needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331984#M74684</link>
      <description>&lt;P&gt;Actually, this code "does" nothing. It only sets macro variables to certain values and puts those values into the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since we don't know the values of &amp;amp;periods, &amp;amp;runout, &amp;amp;run_date and &amp;amp;enrlmntdy, we can't even test that macro code.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 18:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331984#M74684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-12T18:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Code Explanation help needed</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331995#M74685</link>
      <description>&lt;P&gt;Do you not understand the purpose of the code? Or the details of the complex statements?&lt;/P&gt;
&lt;P&gt;The purpose seems to be to calculate start and end periods given a RUN_DATE, PERIODS, RUNOUT and ENRLMNTDY values.&lt;/P&gt;
&lt;P&gt;As to the more complex statement, perhaps they would be easier to understand if the unneeded complexity is removed.&lt;/P&gt;
&lt;P&gt;Change&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_dt1=%sysfunc(inputn(%SYSFUNC(INTNX(MONTH, &amp;amp;RUN_DATE.,%EVAL(-12*&amp;amp;PERIODS.-&amp;amp;RUNOUT.),B),yymmdd8.), yymmdd8.), date9.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_dt1=%sysfunc(intnx(month,&amp;amp;run_date,-12*&amp;amp;periods-&amp;amp;runout,b),date9);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So this statement is saying give me the first date of the month that is &amp;amp;PERIODS years and &amp;amp;RUNOUT months before the date that is in RUN_DATE. &amp;nbsp;And format the values as text string in ddMMMyyyy format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly later on inside of the macro you are getting the LAST day of the same month using the same logic as before.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_dt = %sysfunc(inputn(%SYSFUNC(INTNX(MONTH, &amp;amp;RUN_DATE.,%EVAL(-12*&amp;amp;PERIODS.-&amp;amp;RUNOUT.),E),yymmdd8.), yymmdd8.), date9.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But since you already calculated the first of the month you could just convert it to :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start_dt = %sysfunc(intnx(month,"&amp;amp;start_dt1"d,0,e),date9);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Feb 2017 20:36:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/331995#M74685</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-12T20:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Code Explanation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/332108#M74715</link>
      <description>&lt;P&gt;The purpose of this code is to make me rapidly hit the delete key. &amp;nbsp;It does virtually nothing except sit there as a mass of obfuscated code sucking up valuable programming hours.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 09:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/332108#M74715</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-13T09:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Code Explanation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/332123#M74727</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless there is the need of repeatabilty, no need of macro coding there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All it's doing is conditionally setting a START_DT macro variable, based on some other macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it's really bad macro coding, and it could be done with much simpler/cleaner data step code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
* set 1; 
if symget('ENRLMNTDY') eq '1' then START_DT=1; 
* add 14 days; 
else if symget('ENRLMNTDY') eq '15' then START_DT=intnx('day',"&amp;amp;START_DT1"d,14); 
* add -12*&amp;amp;PERIODS-&amp;amp;ROUNOUT to &amp;amp;RUNDATE and adjust at month's end;
else if upcase(symget('ENRLMNTDY')) eq 'LAST' then START_DT=intnx('month',&amp;amp;RUN_DATE,-12*&amp;amp;PERIODS-&amp;amp;ROUNOUT,'end');
call symput('START_DT',put(START_DT,date9.)); * format and set macro var;
quit;&lt;/CODE&gt;&lt;/PRE&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>Mon, 13 Feb 2017 10:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Code-Explanation/m-p/332123#M74727</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2017-02-13T10:57:20Z</dc:date>
    </item>
  </channel>
</rss>

