<?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: Create macro variables automatically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730618#M227532</link>
    <description>As I see in this case if we wrote it without option "g" then result was same. True?</description>
    <pubDate>Thu, 01 Apr 2021 08:09:21 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-04-01T08:09:21Z</dc:date>
    <item>
      <title>Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730608#M227523</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;User need to define a list of variables in a macro variable called List_Vars.&lt;/P&gt;
&lt;P&gt;I want to create a new macro variable called&amp;nbsp; List_Vars2 that will be same as List_Vars1 but with comma between names.&lt;/P&gt;
&lt;P&gt;I want to create a new macro variable called&amp;nbsp; List_Vars3 that will be same as List_Vars1 but&amp;nbsp; before any name there will be "b."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;when we Run %put&amp;nbsp; &amp;amp;&lt;CODE class=" language-sas"&gt;List_Vars2&amp;nbsp;we&amp;nbsp;will&amp;nbsp;get &lt;STRONG&gt;wealth,age&lt;/STRONG&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;when we Run %put&amp;nbsp; &amp;amp;&lt;CODE class=" language-sas"&gt;List_Vars3&amp;nbsp;we&amp;nbsp;will&amp;nbsp;get &lt;STRONG&gt;b.wealth, b.age&lt;/STRONG&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What&amp;nbsp;is&amp;nbsp;the&amp;nbsp;way&amp;nbsp;to&amp;nbsp;create&amp;nbsp;List_Vars2&amp;nbsp;and&amp;nbsp;List_Vars3&amp;nbsp;automatically?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Please&amp;nbsp;note&amp;nbsp;that&amp;nbsp;in&amp;nbsp;real&amp;nbsp;world&amp;nbsp;the&amp;nbsp;user&amp;nbsp;write&amp;nbsp;many&amp;nbsp;varaibles&amp;nbsp;in&amp;nbsp;List_Vars&amp;nbsp;macro&amp;nbsp;varaible&amp;nbsp;and&amp;nbsp;it&amp;nbsp;will&amp;nbsp;be&amp;nbsp;more&amp;nbsp;efficient&amp;nbsp;that&amp;nbsp;macro&amp;nbsp;varaibles&amp;nbsp;List_Vars2&amp;nbsp;and&amp;nbsp;List_Vars3&amp;nbsp;be&amp;nbsp;created&amp;nbsp;automaticaly.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let List_Vars=wealth age;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 06:32:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730608#M227523</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-04-01T06:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730610#M227525</link>
      <description>&lt;P&gt;Do it in a DATA _NULL_:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let List_Vars=wealth age;

data _null_;
list_vars = "&amp;amp;list_vars.";
length list_vars2 list_vars3 $1000;
list_vars2 = translate(trim(list_vars),","," ");
do i = 1 to countw(list_vars);
  list_vars3 = catx(",",list_vars3,"b."!!scan(list_vars,i));
end;
call symputx("list_vars2",list_vars2,"g");
call symputx("list_vars3",list_vars3,"g");
run;

%put &amp;amp;=list_vars2.;
%put &amp;amp;=list_vars3.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 06:38:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730610#M227525</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T06:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730612#M227527</link>
      <description>Thanks,&lt;BR /&gt;What is the purpose of using "g" in call symputx ?&lt;BR /&gt;call symputx("list_vars2",list_vars2,"g");</description>
      <pubDate>Thu, 01 Apr 2021 07:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730612#M227527</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-04-01T07:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730613#M227528</link>
      <description>&lt;P&gt;As usually, Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;Take a look at&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;CALL SYMPUTX Routine&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"g" makes sure that the newly created macro variable ends up in the global symbol table (useful if the data_null_ step might be run inside a macro).&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 07:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730613#M227528</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T07:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730618#M227532</link>
      <description>As I see in this case if we wrote it without option "g" then result was same. True?</description>
      <pubDate>Thu, 01 Apr 2021 08:09:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730618#M227532</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-04-01T08:09:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730619#M227533</link>
      <description>&lt;P&gt;Absolutely. But if you later wrap that code in a macro, you might not get your expected behavior.&lt;/P&gt;
&lt;P&gt;OTOH, you might want to keep the macro variable within the macro, so you would replace the parameter with "L". Just do not forget about the scope of macro variables.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 08:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730619#M227533</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T08:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create macro variables automatically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730634#M227539</link>
      <description>&lt;P&gt;There are many macros and macro libraries out in the world that deal with macro variables containing a list.&amp;nbsp; A list being a value containing delimited items.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider&amp;nbsp;&lt;STRONG&gt;seplist&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename seplist url "https://www.devenezia.com/downloads/sas/macros/download.php?file=seplist.sas";

%include seplist;

%let varlist = wealth,age;

%let varlist2 = %seplist( %quote(&amp;amp;varlist), indlm=%str(,), prefix=B. );

%put NOTE: &amp;amp;=varlist;
%put NOTE: &amp;amp;=varlist2;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;will LOG&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;NOTE: VARLIST=wealth,age
NOTE: VARLIST2=B.wealth,B.age
&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://www.devenezia.com/downloads/sas/macros/?m=seplist" target="_self"&gt;&lt;STRONG&gt;seplist&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;has a close cousin&amp;nbsp;&lt;A href="https://www.devenezia.com/downloads/sas/macros/?m=split" target="_self"&gt;&lt;STRONG&gt;split&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 10:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-macro-variables-automatically/m-p/730634#M227539</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2021-04-01T10:38:27Z</dc:date>
    </item>
  </channel>
</rss>

