<?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 Variable Not resolving in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630416#M186635</link>
    <description>Double quotes instead of single quotes is half the solution.  &lt;BR /&gt;&lt;BR /&gt;By the time you try to use the macro variables, they no longer exist.  They are local to the %monthly symbol table.  You will need to add this statement after the two %LET statements:&lt;BR /&gt;&lt;BR /&gt;%global &amp;amp;monstrt&amp;amp;j &amp;amp;monend&amp;amp;j;</description>
    <pubDate>Sat, 07 Mar 2020 21:02:20 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2020-03-07T21:02:20Z</dc:date>
    <item>
      <title>Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630394#M186631</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a small utility that can resolve the start and end of every month. The code is running fine all the macro variable are resolving as they should have, but the issue is when&amp;nbsp; I am using those macro variables later in my programming then they are not getting resolved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly find attached the code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS MLOGIC MPRINT SYMBOLGEN;

%MACRO MONTHLY;

%DO J=0 %TO 12;
%LET MONSTRT=STRT;
%LET MONEND=END;


DATA _NULL_;
CALL SYMPUT ("&amp;amp;MONSTRT.&amp;amp;J.",PUT(INTNX("MONTH",TODAY(),&amp;amp;J,"B"),DATE9.));
CALL SYMPUT ("&amp;amp;MONEND.&amp;amp;J.",PUT(INTNX("MONTH",TODAY(),&amp;amp;J,"E"),DATE9.));

RUN;

%END;

%PUT &amp;amp;STRT0 &amp;amp;END0 &amp;amp;STRT1 &amp;amp;END1 &amp;amp;STRT2 &amp;amp;END2 &amp;amp;STRT3 &amp;amp;END4 &amp;amp;STRT5 &amp;amp;END5 &amp;amp;STRT6 &amp;amp;END6
     &amp;amp;STRT7 &amp;amp;END7 &amp;amp;STRT8 &amp;amp;END8 &amp;amp;STRT9 &amp;amp;END9 &amp;amp;STRT10 &amp;amp;END10 &amp;amp;STRT11 &amp;amp;END11 &amp;amp;STRT12 &amp;amp;END12;

%MEND MONTHLY;

%MONTHLY;

DATA TEST;
XX='&amp;amp;STRT0.';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 17:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630394#M186631</guid>
      <dc:creator>aashish_jain</dc:creator>
      <dc:date>2020-03-07T17:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630395#M186632</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272464"&gt;@aashish_jain&lt;/a&gt;&lt;BR /&gt;I think the issue is due to the use of single quotes, which prevents the resolution of macrovariables.&lt;BR /&gt;XX='&amp;amp;STRT0.';&lt;BR /&gt;Please try double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;XX="&amp;amp;STRT0.&lt;SPAN&gt;";&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Best,&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 17:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630395#M186632</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-07T17:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630416#M186635</link>
      <description>Double quotes instead of single quotes is half the solution.  &lt;BR /&gt;&lt;BR /&gt;By the time you try to use the macro variables, they no longer exist.  They are local to the %monthly symbol table.  You will need to add this statement after the two %LET statements:&lt;BR /&gt;&lt;BR /&gt;%global &amp;amp;monstrt&amp;amp;j &amp;amp;monend&amp;amp;j;</description>
      <pubDate>Sat, 07 Mar 2020 21:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630416#M186635</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-03-07T21:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630417#M186636</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
xx=resolve('&amp;amp;STRT0');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Mar 2020 21:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630417#M186636</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-03-07T21:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630420#M186638</link>
      <description>&lt;P&gt;You made LOCAL macro variables, unless there is some earlier code that created STRT0 before you called the macro.&amp;nbsp; You can fix that by not using the legacy CALL SYMPUT() function and instead use the more modern CALL SYMPUTX() function that allows you to make the macro variables in the GLOBAL macro variable scope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the macro processor does not operate on text inside of single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for the %DO loop since you are already running a data step. Just use a regular DO loop instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro monthly;
data _null_;
  do j=0 to 12 ;
    call symputx(cats("&amp;amp;monstrt",j),put(intnx("month",today(),j,"b"),date9.),'g');
    call symputx(cats("&amp;amp;monend",j),put(intnx("month",today(),j,"e"),date9.),'g');
  end;
run;
%mend monthly;

%let monstrt=strt;
%let monend=end;
%monthly;

data test;
  xx="&amp;amp;strt0.";
  put xx=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you did want to use %DO loop then get rid of the DATA step and use %SYSFUNC() instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro monthly;
%local j ;
%do j=0 %to 12 ;
  %global &amp;amp;monstrt.&amp;amp;j &amp;amp;monend.&amp;amp;j ;
  %let &amp;amp;monstrt.&amp;amp;j=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;j,b),date9.);
  %let &amp;amp;monend.&amp;amp;j=%sysfunc(intnx(month,%sysfunc(today()),&amp;amp;j,e),date9.);
%end;
%mend monthly;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 21:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630420#M186638</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-07T21:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Not resolving</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630468#M186653</link>
      <description>&lt;P&gt;Thank you for the quick reply the suggestion you wrote works for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Mar 2020 08:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Not-resolving/m-p/630468#M186653</guid>
      <dc:creator>aashish_jain</dc:creator>
      <dc:date>2020-03-08T08:17:13Z</dc:date>
    </item>
  </channel>
</rss>

