<?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 modify macro variable value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353990#M82711</link>
    <description>&lt;P&gt;I found this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let P = %sysfunc(inputn(%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;D.-1,B)),z6.)),DDMMYYN10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in my mailbox.&lt;/P&gt;
&lt;P&gt;Apart from the fact that it creates a raw value instead of a formatted date (which was expected), it looks like a serious attempt of someone who gets a kick out of hurting him/herself.&lt;/P&gt;
&lt;P&gt;It violates several Maxims, notably Maxim 12 and parts of Maxim 11.&lt;/P&gt;
&lt;P&gt;It is a bear to type correctly (at which it failed anyway), is hard to read for the next maintainer, and hard to debug.&lt;/P&gt;
&lt;P&gt;Instead do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
mydate = intnx(month,today(),&amp;amp;D.-1,"b");
call symputx('P',put(mydate,best.),'g');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and use macro variable P directly, without "&amp;amp;P."d. (where somedate &amp;lt;= &amp;amp;P.)&lt;/P&gt;</description>
    <pubDate>Thu, 27 Apr 2017 06:27:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-04-27T06:27:34Z</dc:date>
    <item>
      <title>Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353628#M82558</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem. I import a macro variable named P from a table. P is a date, ex in my case :01JAN2017&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also import another macro variable named D. D is a number, or can be empty or missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do this in my macro:&lt;/P&gt;&lt;PRE&gt;%if "&amp;amp;D." ne . %then %do;
		%if "&amp;amp;D." ne '' %then %do;
			%let &amp;amp;P. = intnx('month',today(),&amp;amp;D.-1,"BEGINNING");
		%end;
%end;&lt;/PRE&gt;&lt;P&gt;And I have a mistake:&lt;/P&gt;&lt;PRE&gt;ERROR: Expecting a variable name after %LET.
ERROR: Symbolic variable name 01JAN2017 must begin with a letter or underscore.&lt;/PRE&gt;&lt;P&gt;Can you help me to correect this, i can't understand&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 11:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353628#M82558</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-04-26T11:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353645#M82559</link>
      <description>&lt;P&gt;Just looking at the code (not able to run it at the moment), on the surface it looks like you just need to change:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;%let &amp;amp;P = ...&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;to&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;%let P= ...&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 26 Apr 2017 11:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353645#M82559</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2017-04-26T11:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353647#M82560</link>
      <description>&lt;P&gt;Why do you have two if statements doing the same thing? &amp;nbsp;Why are you putting data in macro variables? &amp;nbsp;Why are you doing data processing in macro language? To answer your specific question requires a little debugging, which if your using macro you should know very well. &amp;nbsp;Macro is a text find/replace system, nothing more. &amp;nbsp;So if you do that on:&lt;/P&gt;
&lt;PRE&gt;%let &amp;amp;P. = intnx('month',today(),&amp;amp;D.-1,"BEGINNING");&lt;/PRE&gt;
&lt;P&gt;What you get in Base SAS - which is the actual programming language is:&lt;/P&gt;
&lt;PRE&gt;%let 01JAN2017 = intnx('month',today(),01JAN2017-1,"BEGINNING");&lt;/PRE&gt;
&lt;P&gt;Which you can clearly see is invalid SAS code, variables - and macro - have to start with a non-numeric character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In any event the code given doesn't make much sense. &amp;nbsp;Why would you want a macro variable, and all that macro logic to increment a date by one day? &amp;nbsp;Simply doing:&lt;/P&gt;
&lt;PRE&gt;%let p=01JAN2017;

data want;
  set have;
  where date &amp;gt; "&amp;amp;P."d + 1;
run;&lt;/PRE&gt;
&lt;P&gt;Far simpler. &amp;nbsp;The text p gets replaced in the code to create acurate Base SAS code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 11:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353647#M82560</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T11:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353648#M82561</link>
      <description>&lt;P&gt;&amp;amp;P. resolves to the value of macro variable P, so your %let statement becomes&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let 01JAN2017 = intnx('month',today(),&amp;amp;D.-1,"BEGINNING");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since SAS names cannot start with a digit, this fails. I guess you wanted to do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let P = ....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I also question your logic here, as you assign a complete function call to your presumed macro variable P. P will not resolve to a date, but to the &lt;U&gt;text&lt;/U&gt;&lt;/P&gt;
&lt;PRE&gt;intnx('month',today(),2-1,"BEGINNING");&lt;/PRE&gt;
&lt;P&gt;(supposing macro variable D contains 2), which might or might not work once you use &amp;amp;P. anywhere in SAS code.&lt;/P&gt;
&lt;P&gt;If you want to calculate a date, I suggest you do so in a data step and save the resulting value to a macro variable with call symput. See Maxim 11.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 11:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353648#M82561</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-26T11:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353692#M82576</link>
      <description>&lt;P&gt;Ok, to just to be clear what you are trying to achieve:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;You have a macro variable P containing a date-formatted value (e.g, 01JAN2017)&lt;/LI&gt;&lt;LI&gt;You have another macro variable D, which may contain a number, a missing (period) or be null.&lt;/LI&gt;&lt;LI&gt;If D is a number, it represents a number of months.&lt;/LI&gt;&lt;LI&gt;If D contains a number, you want to adjust the date value of P by the number of months in D.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So how to check what's in D..&amp;nbsp;I used the &lt;STRONG&gt;ANYDIGIT()&lt;/STRONG&gt; function.. The only fiddly bit was having nested &lt;STRONG&gt;%SYSFUNC()&lt;/STRONG&gt; macro functions in the final calculation..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyAdjust(P_Old,D);
  %local P_New;
  %if %sysfunc(anydigit(%str(&amp;amp;d))) %then %let P_New = %sysfunc(intnx(month,%sysfunc(today()),&amp;amp;D.-1,BEGINNING),date9.);
  %put P_Old:&amp;amp;P_Old P_New:&amp;amp;P_New;
%mend;&lt;BR /&gt;
%MyAdjust(01JAN2017,1);
%MyAdjust(01JAN2017,0);
%MyAdjust(01JAN2017,12);
%MyAdjust(01JAN2017,.);
%MyAdjust(01JAN2017,);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;P_Old:01JAN2017 P_New:01APR2017&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;P_Old:01JAN2017 P_New:01MAR2017&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;P_Old:01JAN2017 P_New:01MAR2018&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;P_Old:01JAN2017 P_New:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;FONT face="courier new,courier"&gt;P_Old:01JAN2017 P_New:&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It just won't work for negative values of D because the negative sign counts as non-digit.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353692#M82576</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2017-04-26T13:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353741#M82587</link>
      <description>&lt;P&gt;You may also not be testing what you think you are with this line:&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%if&lt;/FONT&gt; &lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;"&amp;amp;D."&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; ne &lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;.&lt;/FONT&gt; &lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%then&lt;/FONT&gt; &lt;FONT color="#ff0080" face="SAS Monospace" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Please check the log after running this code to see a demonstration.&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="SAS Monospace" size="2"&gt;%macro dummy (d);
%if "&amp;amp;D." ne . %then %do;
   %put D was &amp;amp;d when not equal to .;
%end;
%else %do;
   %put D was &amp;amp;d when equal to .;
%end;%mend;

%dummy(d);
%dummy( );
%dummy(.);

%macro dummy2 (d);
%if &amp;amp;D. ne . %then %do;
   %put D was &amp;amp;d when not equal to .;
%end;
%else %do;
   %put D was &amp;amp;d when equal to .;
%end;
%mend;

%dummy2(d);
%dummy2( );
%dummy2(.);&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353741#M82587</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-26T15:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353749#M82590</link>
      <description>&lt;P&gt;Many thanks Andrew,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But unfortunately D is almost everytime negative &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Do you know how could I do to manage it?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 15:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353749#M82590</guid>
      <dc:creator>fabdu92</dc:creator>
      <dc:date>2017-04-26T15:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro modify macro variable value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353990#M82711</link>
      <description>&lt;P&gt;I found this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let P = %sysfunc(inputn(%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;D.-1,B)),z6.)),DDMMYYN10));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in my mailbox.&lt;/P&gt;
&lt;P&gt;Apart from the fact that it creates a raw value instead of a formatted date (which was expected), it looks like a serious attempt of someone who gets a kick out of hurting him/herself.&lt;/P&gt;
&lt;P&gt;It violates several Maxims, notably Maxim 12 and parts of Maxim 11.&lt;/P&gt;
&lt;P&gt;It is a bear to type correctly (at which it failed anyway), is hard to read for the next maintainer, and hard to debug.&lt;/P&gt;
&lt;P&gt;Instead do&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
mydate = intnx(month,today(),&amp;amp;D.-1,"b");
call symputx('P',put(mydate,best.),'g');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and use macro variable P directly, without "&amp;amp;P."d. (where somedate &amp;lt;= &amp;amp;P.)&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2017 06:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-modify-macro-variable-value/m-p/353990#M82711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-27T06:27:34Z</dc:date>
    </item>
  </channel>
</rss>

