<?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: Creating a list of macro variables for a large list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703703#M215667</link>
    <description>&lt;P&gt;&lt;SPAN&gt;%let numvar = 100;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%let&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;&amp;nbsp;variable1&lt;/STRONG&gt; = age;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable2&lt;/STRONG&gt; = race;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable3&lt;/STRONG&gt; = country;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable4&lt;/STRONG&gt; = marital_status;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*I have to add 96 more variables in this list for macro variables;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*I want to create a loop for proc freq and create excel output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro freq_table;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel file="\\C:\output_frequencies.xlsx";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%do i = 1 %to &amp;amp;numvar; *this will go from 1 to 100;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel options(embedded_titles='on' embedded_footnotes='on' sheet_name=&lt;STRONG&gt;"&amp;amp;&amp;amp;variable&amp;amp;i"&lt;/STRONG&gt; sheet_interval = 'proc');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc freq data = my_data_set varheader = namelabel nosummary;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables&amp;nbsp; X1*V2*&lt;STRONG&gt;&amp;amp;&amp;amp;variable&amp;amp;i&lt;/STRONG&gt;&amp;nbsp;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel close;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%freq_table;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Dec 2020 19:11:06 GMT</pubDate>
    <dc:creator>Emma_at_SAS</dc:creator>
    <dc:date>2020-12-04T19:11:06Z</dc:date>
    <item>
      <title>Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703692#M215662</link>
      <description>&lt;P&gt;I have a large list of variables that I want to use in a loop as&amp;nbsp;&lt;STRONG&gt;*&amp;amp;&amp;amp;variable&amp;amp;i&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Therefore, I want to introduce them as macro variables&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;variable1 = age;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable2 = race;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable3 = country;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable4 = marital_status;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and so on...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I do not want to type "%let&amp;nbsp;variable1", "%let&amp;nbsp;variable2", "%let&amp;nbsp;variable3" before each variable name because my list is so long.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How may I write a code to receive the name of the variables and create the&amp;nbsp;%let&amp;nbsp;variable1 = before each variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 18:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703692#M215662</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2020-12-04T18:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703694#M215663</link>
      <description>&lt;P&gt;Where does the list about the desired variable names reside? In a data set? a single macro variable? if so what does that macro variable look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may also be a good idea to provide how you intend to use the &amp;amp;&amp;amp;variable&amp;amp;i . Sometimes there are clearer ways than the indirect reference.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 18:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703694#M215663</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-04T18:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703695#M215664</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
input value $20.;
call symputx(cats("variable",_n_),value);
datalines;
age
race
country
marital_status
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Dec 2020 18:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703695#M215664</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-04T18:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703700#M215666</link>
      <description>&lt;P&gt;Assuming you want the list of variables from a data set, I would recommend the following approach. Change your library and data set name to get the relevant variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :macroVars1- 
from sashelp.vcolumn
where libname = "SASHELP" and memname = "CLASS"
and upper(name) not in ('NAME', 'SEX');
quit;

*Number of observations stored in automatic macro variables;
%put Number of Macro Variables created : &amp;amp;sqlObs;

*Check assignments;
%put First Macro Variable : &amp;amp;macroVars1.;
%put Last Macro Variable : &amp;amp;&amp;amp;macroVars&amp;amp;sqlObs;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84351"&gt;@Emma_at_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a large list of variables that I want to use in a loop as&amp;nbsp;&lt;STRONG&gt;*&amp;amp;&amp;amp;variable&amp;amp;i&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Therefore, I want to introduce them as macro variables&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;variable1 = age;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable2 = race;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable3 = country;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let variable4 = marital_status;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and so on...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I do not want to type "%let&amp;nbsp;variable1", "%let&amp;nbsp;variable2", "%let&amp;nbsp;variable3" before each variable name because my list is so long.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How may I write a code to receive the name of the variables and create the&amp;nbsp;%let&amp;nbsp;variable1 = before each variable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 18:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703700#M215666</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-04T18:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703703#M215667</link>
      <description>&lt;P&gt;&lt;SPAN&gt;%let numvar = 100;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;%let&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;&amp;nbsp;variable1&lt;/STRONG&gt; = age;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable2&lt;/STRONG&gt; = race;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable3&lt;/STRONG&gt; = country;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;%let variable4&lt;/STRONG&gt; = marital_status;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*I have to add 96 more variables in this list for macro variables;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;*I want to create a loop for proc freq and create excel output;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%macro freq_table;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel file="\\C:\output_frequencies.xlsx";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%do i = 1 %to &amp;amp;numvar; *this will go from 1 to 100;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel options(embedded_titles='on' embedded_footnotes='on' sheet_name=&lt;STRONG&gt;"&amp;amp;&amp;amp;variable&amp;amp;i"&lt;/STRONG&gt; sheet_interval = 'proc');&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;proc freq data = my_data_set varheader = namelabel nosummary;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables&amp;nbsp; X1*V2*&lt;STRONG&gt;&amp;amp;&amp;amp;variable&amp;amp;i&lt;/STRONG&gt;&amp;nbsp;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ods excel close;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%mend;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%freq_table;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2020 19:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703703#M215667</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2020-12-04T19:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703704#M215668</link>
      <description>the desired variable names reside in a data set.&lt;BR /&gt;&lt;BR /&gt;Thank you!</description>
      <pubDate>Fri, 04 Dec 2020 19:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/703704#M215668</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2020-12-04T19:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704237#M215871</link>
      <description>&lt;P&gt;Thank you Reeza for your suggested code. May you please add some notes to it and clarify what each part does? It is above my level of expertise and I cannot use it!&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 18:29:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704237#M215871</guid>
      <dc:creator>Emma_at_SAS</dc:creator>
      <dc:date>2020-12-07T18:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704239#M215872</link>
      <description>&lt;P&gt;If you have the list of variables in a dataset then there is no need for macro variables or macro code at all to do what you want.&lt;/P&gt;
&lt;P&gt;Let's assume you have dataset named CONTENTS with a variable named NAME.&lt;/P&gt;
&lt;P&gt;So you could use a data step to generate a separate PROC step for each observation in CONTENTS.&amp;nbsp; You could use CALL EXECUTE, but I find it easier and clearer to write the code to a file and then %INCLUDE the file.&amp;nbsp; Then you can use PUT statement options like using the $QUOTE format to quoted the NAME when defining the SHEET_NAME.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="\\C:\output_frequencies.xlsx"
 options (embedded_titles='on' embedded_footnotes='on' sheet_interval='proc')
;
filename code temp;
data _null_;
  set contents;
  file code;
  put 'excel options (sheet_name=' name :$quote. ');'
    / 'proc freq data=my_data_set varheader=namelabel nosummary;'
    / '  tables X1*V2*' name ';'
    / 'run;'
  ;
run;
%include code / source2;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Dec 2020 18:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704239#M215872</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-07T18:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of macro variables for a large list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704298#M215902</link>
      <description>I'd actually recommend you run it, add your own comments to what you think is happening and I'll be happy to help. Running it is the best way to learn from it. Comments in this particular case won't help much. &lt;BR /&gt;&lt;BR /&gt;If you need instructions on the basics of working with macro variables using SQL I recommend the following:&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=p0xlnvl46zgqffn17piej7tewe7p.htm&amp;amp;locale=en&lt;/A&gt;</description>
      <pubDate>Mon, 07 Dec 2020 21:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-list-of-macro-variables-for-a-large-list-of-variables/m-p/704298#M215902</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-07T21:59:52Z</dc:date>
    </item>
  </channel>
</rss>

