<?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 Assign Rows of Table to Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680867#M205878</link>
    <description>&lt;P&gt;I have an n x 1 table where I want to assign the values of the rows to macro variables for use in model building. There will be several such tables, all of varying lengths, created during the course of an automated program (so I don't know the number of rows at any given point). I am struggling to think of a way to generalize the code to accomplish this task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input name $;
	datalines;
act_a
act_b
act_c
act_d
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 05:00:56 GMT</pubDate>
    <dc:creator>tburus</dc:creator>
    <dc:date>2020-09-02T05:00:56Z</dc:date>
    <item>
      <title>Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680867#M205878</link>
      <description>&lt;P&gt;I have an n x 1 table where I want to assign the values of the rows to macro variables for use in model building. There will be several such tables, all of varying lengths, created during the course of an automated program (so I don't know the number of rows at any given point). I am struggling to think of a way to generalize the code to accomplish this task.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input name $;
	datalines;
act_a
act_b
act_c
act_d
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 05:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680867#M205878</guid>
      <dc:creator>tburus</dc:creator>
      <dc:date>2020-09-02T05:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680868#M205879</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input name $;
datalines;
act_a
act_b
act_c
act_d
;

 proc sql noprint;
   select name into :n1 -
   from test;
   %let num = &amp;amp;sqlobs;
 quit;

 %put &amp;amp;=n1 &amp;amp;=n2 &amp;amp;=n3 &amp;amp;=n4 &amp;amp;=num;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 05:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680868#M205879</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-09-02T05:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680869#M205880</link>
      <description>&lt;P&gt;Rule of thumb: moving data into macro-variables is a bad idea in almost all cases i can think of, because when creating a lot of variables, or one variable containing a list of values, you will have to write loops to process the information. The BY-statement (usable in many procedures) exists to avoid such coding.&lt;/P&gt;
&lt;P&gt;But since model building is something not on my skill list, creating those macro-variables could be the easiest way to solve your problem - i doubt it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* On variable, values separated by | */
proc sql noprint;
  select name into :nameList separated by '|'
    from test;
quit;

/* One variable for each value */
data _null_;
  set test;
  call symputx(cats('test_', _n_), name);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Sep 2020 05:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680869#M205880</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-09-02T05:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680871#M205882</link>
      <description>&lt;P&gt;Thank you for your caution. If it helps, here is what the model building looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=GLSDesign_basb3;
   	strata strata;
	weight nationalweight;
	tables sport_name_girls_softball*(act_a--act_d)/ or noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The difficulty lies in that sometimes the list may go to act_e or beyond, or there may not be an act_a at the beginning, etc. In order to automate this I need something that generalizes past those uncertainties.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 05:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680871#M205882</guid>
      <dc:creator>tburus</dc:creator>
      <dc:date>2020-09-02T05:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680872#M205883</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329503"&gt;@tburus&lt;/a&gt;&amp;nbsp;if you want to use all variables with the naming pattern act_*** in your tables statement, simply use a variable list like below. I use an example data set, since I don't have access to your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=sashelp.baseball;
   	strata league;
	weight salary;
	tables team*(n:) / or noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you insist on the macro variables approach, see below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input name $;
datalines;
act_a
act_b
act_c
act_d
;

proc sql noprint;
    select name into :n1 -
    from test;
    %let num = &amp;amp;sqlobs;
quit;

%put &amp;amp;n1 &amp;amp;&amp;amp;n&amp;amp;num;

options symbolgen;
proc surveyfreq data=GLSDesign_basb3;
   	strata strata;
	weight nationalweight;
	tables sport_name_girls_softball*(&amp;amp;n1--&amp;amp;&amp;amp;n&amp;amp;num)/ or noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 06:02:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680872#M205883</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-09-02T06:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680879#M205887</link>
      <description>&lt;P&gt;Thanks. I'm not quite sure I see how to implement the first method you mentioned. I have included a list of variable names from one of the tables being used to build the models (these come from a set of dummy variables created using GLMSelect):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="plot.png" style="width: 258px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48858iE5D6C47F98B5CFC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="plot.png" alt="plot.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 06:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680879#M205887</guid>
      <dc:creator>tburus</dc:creator>
      <dc:date>2020-09-02T06:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680892#M205893</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=GLSDESIGN_BASB3;
  strata STRATA;
  weight NATIONALWEIGHT;
  tables SPORT_NAME_GIRLS_SOFTBALL*(ACT_:)/ or noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 08:34:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680892#M205893</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-02T08:34:28Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680918#M205905</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329503"&gt;@tburus&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. I'm not quite sure I see how to implement the first method you mentioned. I have included a list of variable names from one of the tables being used to build the models (these come from a set of dummy variables created using GLMSelect):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="plot.png" style="width: 258px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48858iE5D6C47F98B5CFC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="plot.png" alt="plot.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would use the first method from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;where the separator is a space, rather than a vertical bar as he had. Then your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyfreq data=GLSDesign_basb3;
   	strata strata;
	weight nationalweight;
	tables sport_name_girls_softball*(&amp;amp;namelist)/ or noprint;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is perfectly general, works for any text in data set TEST, and any number of rows in the data set TEST (assuming the text is a legal SAS variable name).&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/680918#M205905</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-02T10:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: Assign Rows of Table to Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/681044#M205948</link>
      <description>I can honesty say I am blown away that works. Thanks a bunch.</description>
      <pubDate>Wed, 02 Sep 2020 15:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-Rows-of-Table-to-Macro-Variables/m-p/681044#M205948</guid>
      <dc:creator>tburus</dc:creator>
      <dc:date>2020-09-02T15:58:35Z</dc:date>
    </item>
  </channel>
</rss>

