<?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: how to create global variable with suffix in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321354#M70938</link>
    <description>&lt;P&gt;hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote an answer and my real problem while you were editing and changing your first reply...all my writing is in nirvana now...&lt;/P&gt;&lt;P&gt;Anyway, short story:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can reference my newly created variables without problems:&lt;/P&gt;&lt;PRE&gt;%init_web_parameter(sk_fg sk_fg_txt);
%put &amp;amp;=sk_fg;
%put &amp;amp;=sk_fg_txt;&lt;/PRE&gt;&lt;P&gt;this works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how do I have to reference EXAMPLE_txt if I have the name "EXAMPLE" in another variable?&lt;/P&gt;&lt;PRE&gt;%let EXAMPLE_txt=;
%let xxx=EXAMPLE;
%let yyy=&amp;amp;&amp;amp;&amp;amp;xxx._txt;&lt;/PRE&gt;&lt;P&gt;so yyy contains &amp;amp;EXAMPLE_txt.....&amp;nbsp; (see my second log)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expected&amp;nbsp;yyy&amp;nbsp;resulting in an empty string.&lt;/P&gt;&lt;P&gt;Where is my mistake?&lt;/P&gt;&lt;P&gt;thank you very much in advance,&lt;/P&gt;&lt;P&gt;defaz&lt;/P&gt;</description>
    <pubDate>Tue, 27 Dec 2016 22:22:26 GMT</pubDate>
    <dc:creator>defaz</dc:creator>
    <dc:date>2016-12-27T22:22:26Z</dc:date>
    <item>
      <title>how to create global variable with suffix in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321282#M70914</link>
      <description>&lt;P&gt;hi to all,&lt;/P&gt;&lt;P&gt;I try to create global variables with a macro. It works flawless with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;%macro init_web_parameter(varlist);
 options symbolgen;
 %put XXXXXXVARLIST: &amp;amp;varlist;
 %let L_cnt=1;
 %let L_var=%qscan(%quote(&amp;amp;varlist.),&amp;amp;L_cnt.,%str( ));
 %do %while(&amp;amp;L_var ne %nrstr( )); 
    
		%if (%symexist(&amp;amp;L_var.) = 0) %then %do;
			%global &amp;amp;L_var  ; 
			%let &amp;amp;L_var      = ;
                        %put XXXXXX&amp;amp;L_Var: # &amp;amp;L_var._txt # &amp;amp;&amp;amp;&amp;amp;L_var._txt # &amp;amp;sk_fg_txt #;
		%end;

    %let L_cnt=%eval(&amp;amp;L_cnt+1);
    %let L_var=%qscan(%quote(&amp;amp;varlist.),&amp;amp;L_cnt.,%str( ));
 %end;
 options nosymbolgen;
	
%mend;

%init_web_parameter(sk_fg sk_fg_txt)&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;here is the log:&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg sk_fg_txt
XXXXXXVARLIST: sk_fg sk_fg_txt
SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg sk_fg_txt
SYMBOLGEN:  Macro variable L_CNT resolves to 1
SYMBOLGEN:  Macro variable L_VAR resolves to sk_fg
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
...
WARNING: Apparent symbolic reference SK_FG_TXT not resolved.
XXXXXXsk_fg: # sk_fg_txt # &amp;amp;amp;sk_fg_txt # &amp;amp;amp;sk_fg_txt #
                                                                                          The SAS System

SYMBOLGEN:  Macro variable L_CNT resolves to 1
SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg sk_fg_txt
SYMBOLGEN:  Macro variable L_CNT resolves to 2
...
SYMBOLGEN:  Macro variable SK_FG_TXT resolves to 
XXXXXXsk_fg_txt: # sk_fg_txt_txt # &amp;amp;amp;sk_fg_txt_txt #  #&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;but when I try to create additional variables with a suffix, I run into problem:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;%macro init_web_parameter(varlist);
 options symbolgen;
 %put XXXXXXVARLIST: &amp;amp;varlist;
 %let L_cnt=1;
 %let L_var=%qscan(%quote(&amp;amp;varlist.),&amp;amp;L_cnt.,%str( ));
 %do %while(&amp;amp;L_var ne %nrstr( )); 
    
		%if (%symexist(&amp;amp;L_var.) = 0) %then %do;
			%global &amp;amp;L_var  &amp;amp;L_var._txt  ; 
			%let &amp;amp;L_var      = ;
			%let &amp;amp;L_var._txt = ; 
                        %put XXXXXX&amp;amp;L_Var: # &amp;amp;L_var._txt # &amp;amp;&amp;amp;&amp;amp;L_var._txt # &amp;amp;sk_fg_txt #;
		%end;

    %let L_cnt=%eval(&amp;amp;L_cnt+1);
    %let L_var=%qscan(%quote(&amp;amp;varlist.),&amp;amp;L_cnt.,%str( ));
 %end;
 options nosymbolgen;
	
%mend;

%init_web_parameter(sk_fg); /* sk_fg_txt)    */

&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;and again the log:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg
XXXXXXVARLIST: sk_fg
SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg
SYMBOLGEN:  Macro variable L_CNT resolves to 1
SYMBOLGEN:  Macro variable L_VAR resolves to sk_fg
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN:  &amp;amp;amp;&amp;amp;amp; resolves to &amp;amp;amp;.
                                                                                          The SAS System

SYMBOLGEN:  Macro variable L_VAR resolves to sk_fg
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN:  Macro variable SK_FG_TXT resolves to 
XXXXXXsk_fg: # sk_fg_txt # &amp;amp;amp;sk_fg_txt #  #
SYMBOLGEN:  Macro variable L_CNT resolves to 1
SYMBOLGEN:  Macro variable VARLIST resolves to sk_fg
SYMBOLGEN:  Macro variable L_CNT resolves to 2
SYMBOLGEN:  Macro variable L_VAR resolves to 
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;how do I have to reference sk_fg_txt ??????&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;It oviously&amp;nbsp;contains an empty string (value between the last 2 hashes), but I can't get the value by an indirect reference on the veriable name...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;What is my mistake?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;thank you very much in advance,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;defaz&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2016 11:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321282#M70914</guid>
      <dc:creator>defaz</dc:creator>
      <dc:date>2016-12-27T11:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to create global variable with suffix in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321294#M70915</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that you set no value for the macro variable :&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="3" face="Courier New"&gt;%let &amp;amp;L_var._txt = ;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;If you replace the statement , for example, with&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="3" face="Courier New"&gt;%let &amp;amp;L_var._txt = some;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;you will notice the result is displayed correctly . &lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2016 14:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321294#M70915</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-12-27T14:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to create global variable with suffix in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321353#M70937</link>
      <description>&lt;P&gt;Here some code variations which should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro init_web_parameter(varlist);
  %do i=1 %to %sysfunc(countw(&amp;amp;varlist));
    %global %qscan(&amp;amp;varlist,&amp;amp;i);
    %put macro var is: &amp;amp;%qscan(&amp;amp;varlist,&amp;amp;i);
  %end;
%mend;

%init_web_parameter(sk_fg sk_fg_txt);
%put &amp;amp;=sk_fg;
%put &amp;amp;=sk_fg_txt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also use parmbuff (example 3 under below link)&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1nypovnwon4uyn159rst8pgzqrl.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/69726/HTML/default/viewer.htm#p1nypovnwon4uyn159rst8pgzqrl.htm&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro init_web_parameter / parmbuff;
  %do i=1 %to %sysfunc(countw(&amp;amp;SYSPBUFF));
    %global %qscan(&amp;amp;SYSPBUFF,&amp;amp;i);
    %put macro var is: &amp;amp;%qscan(&amp;amp;SYSPBUFF,&amp;amp;i);
  %end;
%mend;

%init_web_parameter(purple red blue teal);&lt;/CODE&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2016 22:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321353#M70937</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-27T22:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to create global variable with suffix in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321354#M70938</link>
      <description>&lt;P&gt;hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote an answer and my real problem while you were editing and changing your first reply...all my writing is in nirvana now...&lt;/P&gt;&lt;P&gt;Anyway, short story:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can reference my newly created variables without problems:&lt;/P&gt;&lt;PRE&gt;%init_web_parameter(sk_fg sk_fg_txt);
%put &amp;amp;=sk_fg;
%put &amp;amp;=sk_fg_txt;&lt;/PRE&gt;&lt;P&gt;this works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how do I have to reference EXAMPLE_txt if I have the name "EXAMPLE" in another variable?&lt;/P&gt;&lt;PRE&gt;%let EXAMPLE_txt=;
%let xxx=EXAMPLE;
%let yyy=&amp;amp;&amp;amp;&amp;amp;xxx._txt;&lt;/PRE&gt;&lt;P&gt;so yyy contains &amp;amp;EXAMPLE_txt.....&amp;nbsp; (see my second log)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expected&amp;nbsp;yyy&amp;nbsp;resulting in an empty string.&lt;/P&gt;&lt;P&gt;Where is my mistake?&lt;/P&gt;&lt;P&gt;thank you very much in advance,&lt;/P&gt;&lt;P&gt;defaz&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2016 22:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321354#M70938</guid>
      <dc:creator>defaz</dc:creator>
      <dc:date>2016-12-27T22:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to create global variable with suffix in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321355#M70939</link>
      <description>&lt;P&gt;The code I've posted creates as many macro variables as there are words in the string you pass to the macro. That's what I understood you're after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"But how do I have to reference EXAMPLE_txt if I have the name "EXAMPLE" in another variable?"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I don't understand your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for your code: You're creating macro variables in a loop but you have already a %put statement in there with fixed names - so that's firstly no more dynamic and 2nd that's why you get a Warning in the log during the first iteration of the macro loop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your testing: Make sure that you always create a new SAS session so you don't miss issues due to macro variables already existing from an earlier test.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 03:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-global-variable-with-suffix-in-macro/m-p/321355#M70939</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-12-28T03:15:35Z</dc:date>
    </item>
  </channel>
</rss>

