<?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: Issues with Macro syntax in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32258#M6243</link>
    <description>Peter, it is a piece of code in a program I have inherited and I just wanted to get my head around exactly what it was doing. I think your explanation plus a little bit of playing around has given me enough of an insight now to understand why it is there.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your time!</description>
    <pubDate>Thu, 11 Nov 2010 15:46:32 GMT</pubDate>
    <dc:creator>embee47</dc:creator>
    <dc:date>2010-11-11T15:46:32Z</dc:date>
    <item>
      <title>Issues with Macro syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32256#M6241</link>
      <description>As a SAS novice I need someone to spell out exactly, in layman's terms, what is happening in the bold bits here:&lt;BR /&gt;
&lt;BR /&gt;
rsubmit;&lt;BR /&gt;
%let shift_today=&lt;B&gt;intnx('month',today(),-1);&lt;/B&gt;&lt;BR /&gt;
%let month_criteria&lt;B&gt;=(year(&amp;amp;shift_today)*100+month(&amp;amp;shift_today));&lt;/B&gt;&lt;BR /&gt;
endrsubmit;&lt;BR /&gt;
&lt;BR /&gt;
I 'think' it is saying shift_today is a month and is always one month before the current month. So shift_today would be October?&lt;BR /&gt;
&lt;BR /&gt;
The month_criteria I don't get!&lt;BR /&gt;
&lt;BR /&gt;
any help would be massively appreciated! Thanks</description>
      <pubDate>Thu, 11 Nov 2010 12:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32256#M6241</guid>
      <dc:creator>embee47</dc:creator>
      <dc:date>2010-11-11T12:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Macro syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32257#M6242</link>
      <description>these statements are not executed in the lines you show here. &lt;BR /&gt;
These lines prepare strings which would execute validly in other contexts when the code refers to &amp;amp;shift_today or &amp;amp;month_criteria&lt;BR /&gt;
 &lt;BR /&gt;
The first of these statements will derive a date (number of days since 1960) for the first of the month before the datetime when that syntax is finally executed.&lt;BR /&gt;
The second is an attempt (which might work) to derive the date string YYYYMM for the month before the month when that &amp;amp;month_criteria is resolved/executed. &lt;BR /&gt;
 &lt;BR /&gt;
it could be done so much more reliably, and understandably (imho)&lt;BR /&gt;
&lt;BR /&gt;
Normally a macro variable &amp;amp;something is a convenient way of re-using a constant.&lt;BR /&gt;
The risk with using &amp;amp;month_criteria more than once in a sas program occurs when the sas program starts just before midnight at the end of a month - and there is a chance (=risk) that a subsequent use of &amp;amp;month_criteria in the same sas program would execute after that midnight - and so return a different "month". That is not normally what one would want.&lt;BR /&gt;
 &lt;BR /&gt;
Rather than store syntax in &amp;amp;month_criteria, store the value, with&lt;BR /&gt;
%let month_criteria = %sysfunc( intnx( month, "&amp;amp;sysdate"d, -1), yymmN6 ) ;&lt;BR /&gt;
where &amp;amp;sysdate is the built-in string for the start date of the SAS system which runs the program.&lt;BR /&gt;
&lt;BR /&gt;
Then all references to &amp;amp;month_criteria will result in the same string.&lt;BR /&gt;
&lt;BR /&gt;
and if you are invoking my code in a server that runs for many days- and so may have historic start date, replace "&amp;amp;sysdate"d with %sysfunc(date())&lt;BR /&gt;
 &lt;BR /&gt;
Of course if the purpose of the statement&lt;BR /&gt;
%let month_criteria=(year(&amp;amp;shift_today)*100+month(&amp;amp;shift_today));&lt;BR /&gt;
is to confuse, or to prepare an explanation&lt;BR /&gt;
it may achieve its purpose.&lt;BR /&gt;
but I don't know what the author had in mind&lt;BR /&gt;
 &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 11 Nov 2010 15:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32257#M6242</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-11-11T15:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Macro syntax</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32258#M6243</link>
      <description>Peter, it is a piece of code in a program I have inherited and I just wanted to get my head around exactly what it was doing. I think your explanation plus a little bit of playing around has given me enough of an insight now to understand why it is there.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your time!</description>
      <pubDate>Thu, 11 Nov 2010 15:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Macro-syntax/m-p/32258#M6243</guid>
      <dc:creator>embee47</dc:creator>
      <dc:date>2010-11-11T15:46:32Z</dc:date>
    </item>
  </channel>
</rss>

