<?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: Multiple function in macro variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875248#M42930</link>
    <description>&lt;P&gt;Do you want the number of the month of the previous day?&amp;nbsp; That is what it looks like your code is trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(month( %sysfunc(today())-1 ),z2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want the number of the previous month?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(month( %sysfunc(intnx(month, %sysfunc(today()) ,-1)) ),Z2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;9211   %put %sysfunc(month( %sysfunc(today())-1 ),z2.);
05
9212   %put %sysfunc(month( %sysfunc(intnx(month, %sysfunc(today()) ,-1)) ),Z2.);
04
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2023 15:09:05 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-11T15:09:05Z</dc:date>
    <item>
      <title>Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875136#M42921</link>
      <description>May i know why my macro variable hit error =“ expected close parenthesis after macro function invocation not found”&lt;BR /&gt;&lt;BR /&gt;I wanna get the value 04 assuming now is MAY2023&lt;BR /&gt;&lt;BR /&gt;/*Here my code*/&lt;BR /&gt;&lt;BR /&gt;%Let PrevMonth = %sysfunc (month(%sysfunc(today()))-1);&lt;BR /&gt;&lt;BR /&gt;Proc sql;&lt;BR /&gt;Create table abc (date num format=z2.);&lt;BR /&gt;Insert into abc values (&amp;amp;PrevMonth);</description>
      <pubDate>Thu, 11 May 2023 04:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875136#M42921</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-11T04:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875138#M42922</link>
      <description>&lt;P&gt;The -1 portion needs an %eval or equivalent type of function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 05:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875138#M42922</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-11T05:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875139#M42923</link>
      <description>&lt;P&gt;You have a -1 inside the outer call to %sysfunc. In effect:&amp;nbsp; %sysfunc(&amp;lt;some result&amp;gt; -1) and %sysfunc does not know how to use that.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;%Let PrevMonth = %sysfunc (month( %sysfunc( today() ) ));
%put Prevmonth here is: &amp;amp;prevmonth;

%let PrevMonth = %eval(%sysfunc (month( %sysfunc( today() ) )) -1);
%put PrevMonth here is: &amp;amp;prevmonth;&lt;/PRE&gt;
&lt;P&gt;The macro language generally does not "do arithmetic" unless specifically called to with %eval (integers) or %sysevalf (decimals)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you truly need 04 and not 4 then you need yet another step to place the 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442441"&gt;@ChrisWoo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;May i know why my macro variable hit error =“ expected close parenthesis after macro function invocation not found”&lt;BR /&gt;&lt;BR /&gt;I wanna get the value 04 assuming now is MAY2023&lt;BR /&gt;&lt;BR /&gt;/*Here my code*/&lt;BR /&gt;&lt;BR /&gt;%Let PrevMonth = %sysfunc (month(%sysfunc(today()))-1);&lt;BR /&gt;&lt;BR /&gt;Proc sql;&lt;BR /&gt;Create table abc (date num format=z2.);&lt;BR /&gt;Insert into abc values (&amp;amp;PrevMonth);&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 05:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875139#M42923</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-11T05:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875140#M42924</link>
      <description>&lt;P&gt;Each %SYSFUNC call needs two right ).&amp;nbsp; One to end the function you are calling and one to end the %SYSFUNC call.&lt;/P&gt;
&lt;P&gt;You have one in the wrong place.&lt;/P&gt;
&lt;P&gt;Let's work our way from the innermost out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(today())
%sysfunc(today())-1
%sysfunc(month( %sysfunc(today())-1 ))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 05:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875140#M42924</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-11T05:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875146#M42925</link>
      <description>Hi ballardw,&lt;BR /&gt;&lt;BR /&gt;I got my value as 4 by using %eval, may I know what’s that additional step to make it 04? By formatting it ?</description>
      <pubDate>Thu, 11 May 2023 06:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875146#M42925</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-11T06:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875243#M42928</link>
      <description>&lt;P&gt;What happens in January? You'll get a 0....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let PrevMonth = %sysfunc(intnx(month, %sysfunc(today()), -1, s), mmddyy2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use INTNX to move the date one month back.&lt;/P&gt;
&lt;P&gt;Use Today to get the current date&lt;/P&gt;
&lt;P&gt;SYSFUNC has a second parameter which is the format, use the mmddyy2 format to get just the month number with the leading zero. The 2, takes only the first two characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 14:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875243#M42928</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-11T14:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875246#M42929</link>
      <description>&lt;P&gt;The macro language does not do arithmetic.&amp;nbsp; But %SYSFUNC() is pushing what you pass to SAS to run.&amp;nbsp; So you can use arithmetic in the arguments passed to the SAS functions by %SYSFUNC().&lt;/P&gt;
&lt;P&gt;This function&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(month( %sysfunc(today())-1 ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will return the month number for yesterday instead of for today.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want it to add a leading zero when the month is before October then add the optional format specification to the outer %SYSFUNC() call.&lt;/P&gt;
&lt;PRE&gt;9206   %put %sysfunc(month( %sysfunc(today())-1 ));
5
9207   %put %sysfunc(month( %sysfunc(today())-1 ),z2.);
05

&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 May 2023 15:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875246#M42929</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-11T15:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875248#M42930</link>
      <description>&lt;P&gt;Do you want the number of the month of the previous day?&amp;nbsp; That is what it looks like your code is trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(month( %sysfunc(today())-1 ),z2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want the number of the previous month?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %sysfunc(month( %sysfunc(intnx(month, %sysfunc(today()) ,-1)) ),Z2.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;9211   %put %sysfunc(month( %sysfunc(today())-1 ),z2.);
05
9212   %put %sysfunc(month( %sysfunc(intnx(month, %sysfunc(today()) ,-1)) ),Z2.);
04
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 15:09:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875248#M42930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-11T15:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple function in macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875254#M42931</link>
      <description>thanks mate. I was initially thinking to modify manually every January of the year.... haha</description>
      <pubDate>Thu, 11 May 2023 15:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Multiple-function-in-macro-variable/m-p/875254#M42931</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-05-11T15:31:45Z</dc:date>
    </item>
  </channel>
</rss>

