<?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: Nested macro with nrstr in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594376#M170756</link>
    <description>&lt;P&gt;Show us a larger part of the code, including the definitions of the macros. Run the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then show us the entire log (not just the errors and warnings).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also the part you show has imbalanced parentheses.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Why use %NRSTR() here anyway? Why not call %LOWER inside %UPPER instead of using %NRSTR() to include %LOWER as an argument?&lt;/P&gt;</description>
    <pubDate>Sun, 06 Oct 2019 22:32:58 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-10-06T22:32:58Z</dc:date>
    <item>
      <title>Nested macro with nrstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594374#M170755</link>
      <description>&lt;P&gt;I use nested macro, upper-level and lower-level ones. As seen below (I modified the code a bit to display here), my lower-level macro take &amp;amp;xtr_var for its arguments, so I use %nrstr in the argument for %upper. But the issue I face now is that SAS can't resolve lower-level macro's arguments, i.e., listname and new. Could anybody help me to solve this issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%upper (statement= %nrstr(	
		%lower(listname=set_list, new= &amp;amp;xth_var);%put &amp;amp;set_list;
....
)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;WARNING: Apparent symbolic reference LISTNAME not resolved.
&amp;amp;listname
WARNING: Apparent symbolic reference NEW not resolved.
&amp;amp;new
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 22:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594374#M170755</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-06T22:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macro with nrstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594376#M170756</link>
      <description>&lt;P&gt;Show us a larger part of the code, including the definitions of the macros. Run the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint mlogic symbolgen;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then show us the entire log (not just the errors and warnings).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Also the part you show has imbalanced parentheses.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Why use %NRSTR() here anyway? Why not call %LOWER inside %UPPER instead of using %NRSTR() to include %LOWER as an argument?&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 22:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594376#M170756</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-06T22:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macro with nrstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594378#M170758</link>
      <description>&lt;P&gt;Thanks. The below is my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop3 (list1=, statement=);
	%if &amp;amp;list1=  %then %let N1= 1;	%else 
		%do; 	%let N1= %sysfunc(countw(&amp;amp;list1));	%end;
	%do x= 1 %to &amp;amp;N1;
		%let xth_var= %scan(&amp;amp;list1, &amp;amp;x);
		%unquote(&amp;amp;STATEMENT);
	%end;
%mend;

%macro let_cumulative (listname, new, RepeatedNo);
	%if &amp;amp;RepeatedNo= 1 %then 
		%do; %global &amp;amp;listname; %end; 
	%else			
		%do; %let &amp;amp;listname= &amp;amp;&amp;amp;&amp;amp;listname &amp;amp;new; %end;
/*	%put "list after=" &amp;amp;listname;*/
%mend;
		
option mlogic mprint symbolgen;
%symdel set_list;
%loop3 (list1= 1 2 3, statement= %nrstr(	
	%let_cumulative (listname=set_list, new= &amp;amp;xth_var,RepeatedNo=&amp;amp;x);%put &amp;amp;set_list;
	%put &amp;amp;listname;
	%put &amp;amp;new;
	%put &amp;amp;RepatedNo;
/*		%let addset= rcult.r_comp_&amp;amp;xth_var.;*/
/*		%let set_list= &amp;amp;set_list &amp;amp;addset;*/
	));
%put &amp;amp;set_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The below is printed in the log window.&lt;/P&gt;
&lt;PRE&gt;6823
6824  %macro loop3 (list1=, statement=);
6825      %if &amp;amp;list1=  %then %let N1= 1;  %else
6826          %do;    %let N1= %sysfunc(countw(&amp;amp;list1));  %end;
6827      %do x= 1 %to &amp;amp;N1;
6828          %let xth_var= %scan(&amp;amp;list1, &amp;amp;x);
6829          %unquote(&amp;amp;STATEMENT);
6830      %end;
6831  %mend;
6832
6833  %macro let_cumulative (listname, new, RepeatedNo);
6834      %if &amp;amp;RepeatedNo= 1 %then
6835          %do; %global &amp;amp;listname; %end;
6836      %else
6837          %do; %let &amp;amp;listname= &amp;amp;&amp;amp;&amp;amp;listname &amp;amp;new; %end;
6838  /*  %put "list after=" &amp;amp;listname;*/
6839  %mend;
6840
6841  option mlogic mprint symbolgen;
6842  %symdel set_list;
6843  %loop3 (list1= 1 2, statement= %nrstr(
MLOGIC(LOOP3):  Beginning execution.
6844      %let_cumulative (listname=set_list, new= &amp;amp;xth_var,RepeatedNo=&amp;amp;x);%put &amp;amp;set_list;
6845      %put &amp;amp;listname;
6846      %put &amp;amp;new;
6847      %put &amp;amp;RepatedNo;
6848  /*      %let addset= rcult.r_comp_&amp;amp;xth_var.;*/
6849  /*      %let set_list= &amp;amp;set_list &amp;amp;addset;*/
6850      ));
MLOGIC(LOOP3):  Parameter LIST1 has value 1 2
MLOGIC(LOOP3):  Parameter STATEMENT has value &amp;#1;     &amp;#16;let_cumulative (listname&amp;#28;set_list&amp;#30; new&amp;#28;
      &amp;#15;xth_var&amp;#30;RepeatedNo&amp;#28;&amp;#15;x)&amp;#14;&amp;#16;put &amp;#15;set_list&amp;#14;     &amp;#16;put &amp;#15;listname&amp;#14;     &amp;#16;put &amp;#15;new&amp;#14;     &amp;#16;put &amp;#15;RepatedNo&amp;#14;
            &amp;#2;
SYMBOLGEN:  Macro variable LIST1 resolves to 1 2
MLOGIC(LOOP3):  %IF condition &amp;amp;list1= is FALSE
MLOGIC(LOOP3):  %LET (variable name is N1)
SYMBOLGEN:  Macro variable LIST1 resolves to 1 2
SYMBOLGEN:  Macro variable N1 resolves to 2
MLOGIC(LOOP3):  %DO loop beginning; index variable X; start value is 1; stop value is 2; by value is
      1.
MLOGIC(LOOP3):  %LET (variable name is XTH_VAR)
SYMBOLGEN:  Macro variable LIST1 resolves to 1 2
SYMBOLGEN:  Macro variable X resolves to 1
SYMBOLGEN:  Macro variable STATEMENT resolves to      %let_cumulative (listname=set_list, new=
            &amp;amp;xth_var,RepeatedNo=&amp;amp;x);%put &amp;amp;set_list;     %put &amp;amp;listname;     %put &amp;amp;new;     %put
            &amp;amp;RepatedNo;
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
MLOGIC(LET_CUMULATIVE):  Beginning execution.
SYMBOLGEN:  Macro variable XTH_VAR resolves to 1
SYMBOLGEN:  Macro variable X resolves to 1
MLOGIC(LET_CUMULATIVE):  Parameter LISTNAME has value set_list
MLOGIC(LET_CUMULATIVE):  Parameter NEW has value 1
MLOGIC(LET_CUMULATIVE):  Parameter REPEATEDNO has value 1
SYMBOLGEN:  Macro variable REPEATEDNO resolves to 1
MLOGIC(LET_CUMULATIVE):  %IF condition &amp;amp;RepeatedNo= 1 is TRUE
MLOGIC(LET_CUMULATIVE):  %GLOBAL  &amp;amp;LISTNAME
SYMBOLGEN:  Macro variable LISTNAME resolves to set_list
MLOGIC(LET_CUMULATIVE):  Ending execution.
MPRINT(LOOP3):  ;
SYMBOLGEN:  Macro variable SET_LIST resolves to

WARNING: Apparent symbolic reference LISTNAME not resolved.
&amp;amp;listname
WARNING: Apparent symbolic reference NEW not resolved.
&amp;amp;new
WARNING: Apparent symbolic reference REPATEDNO not resolved.
&amp;amp;RepatedNo
MPRINT(LOOP3):   ;
MLOGIC(LOOP3):  %DO loop index variable X is now 2; loop will iterate again.
MLOGIC(LOOP3):  %LET (variable name is XTH_VAR)
SYMBOLGEN:  Macro variable LIST1 resolves to 1 2
SYMBOLGEN:  Macro variable X resolves to 2
SYMBOLGEN:  Macro variable STATEMENT resolves to      %let_cumulative (listname=set_list, new=
            &amp;amp;xth_var,RepeatedNo=&amp;amp;x);%put &amp;amp;set_list;     %put &amp;amp;listname;     %put &amp;amp;new;     %put
            &amp;amp;RepatedNo;
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
MLOGIC(LET_CUMULATIVE):  Beginning execution.
SYMBOLGEN:  Macro variable XTH_VAR resolves to 2
SYMBOLGEN:  Macro variable X resolves to 2
MLOGIC(LET_CUMULATIVE):  Parameter LISTNAME has value set_list
MLOGIC(LET_CUMULATIVE):  Parameter NEW has value 2
MLOGIC(LET_CUMULATIVE):  Parameter REPEATEDNO has value 2
SYMBOLGEN:  Macro variable REPEATEDNO resolves to 2
MLOGIC(LET_CUMULATIVE):  %IF condition &amp;amp;RepeatedNo= 1 is FALSE
SYMBOLGEN:  Macro variable LISTNAME resolves to set_list
MLOGIC(LET_CUMULATIVE):  %LET (variable name is set_list)
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable LISTNAME resolves to set_list
SYMBOLGEN:  Macro variable SET_LIST resolves to
SYMBOLGEN:  Macro variable NEW resolves to 2
MLOGIC(LET_CUMULATIVE):  Ending execution.
MPRINT(LOOP3):  ;
SYMBOLGEN:  Macro variable SET_LIST resolves to 2
2
WARNING: Apparent symbolic reference LISTNAME not resolved.
&amp;amp;listname
WARNING: Apparent symbolic reference NEW not resolved.
&amp;amp;new
WARNING: Apparent symbolic reference REPATEDNO not resolved.
&amp;amp;RepatedNo
MPRINT(LOOP3):   ;
MLOGIC(LOOP3):  %DO loop index variable X is now 3; loop will not iterate again.
MLOGIC(LOOP3):  Ending execution.
6851  %put &amp;amp;set_list;
SYMBOLGEN:  Macro variable SET_LIST resolves to 2
2
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 22:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594378#M170758</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2019-10-06T22:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macro with nrstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594384#M170760</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;FONT color="#FF0000"&gt;SYMBOLGEN: Macro variable SET_LIST resolves to&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SET_LIST resolves to &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then nothing is shown. You have not provided a value for SET_LIST, so nothing after that will work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I still suspect you have overcomplicated the whole thing, and maybe something like this would be easier to code and debug and understand. I show the outline of the code only (and I have no idea what this code is supposed to do anyway):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop3(list1=,statement=,new=,repeatedno=);
%if &amp;amp;list1=  %then %let N1= 1;	
%else %do; 	
    %let N1= %sysfunc(countw(&amp;amp;list1));	
%end;
%do x= 1 %to &amp;amp;N1;
    %let xth_var= %scan(&amp;amp;list1, &amp;amp;x);
    %let_cumulative(listname=set_list,new=x&amp;amp;th_var,repeatedno=&amp;amp;x)
...
%mend;
%macro let_cumulative(listname=,new=,repeatedno=);
...
%mend;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As I said, I think it could be simplified even further, but I don't know what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lastly, I absolutely hate the idea of a macro whose name begins with %LET such as %LET_CUMULATIVE, because %LET is a command with a specific meaning is the macro processor.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Oct 2019 23:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594384#M170760</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-06T23:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Nested macro with nrstr</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594395#M170764</link>
      <description>&lt;P&gt;What the heck are you actually trying to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway the "statements" you are passing to LOOP3 three don't make much sense. You are trying to reference the parameters (like LISTNAME) to the %LET_CUMULATIVE() macro outside of that macro's scope.&amp;nbsp; Those are LOCAL macro variables to that macro and disappear when the macro is finished running.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2019 01:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-macro-with-nrstr/m-p/594395#M170764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-07T01:40:07Z</dc:date>
    </item>
  </channel>
</rss>

