<?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: Run a macro on a set of columns/variables of a dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934966#M42013</link>
    <description>&lt;P&gt;Something like this should do the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SetWithVariablesNames;
input variableName $ 32.;
cards;
n_Mod1_PS 
n_Mod2_PS
...
n_Mod99_PS
n_Mod1_CV 
n_Mod2_CV
...
n_Mod99_CV 
n_Mod1_INF
n_Mod2_INF
...
n_Mod99_INF
;
run;

data _null_;
  set SetWithVariablesNames;
  call execute('%nrstr(%glm(TSM_Mods, ' !! variableName !! ', count))');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming the data sets with your variables exists you can use the following PROC TRANSPOSE trick to get list of selected variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose 
  data = TSM_Mods(obs=0 keep=n_Mod:) /* &amp;lt;--- select variables you need */
  out = SetWithVariablesNames(rename=(_name_=variableName));
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2024 14:21:41 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2024-07-08T14:21:41Z</dc:date>
    <item>
      <title>Run a macro on a set of columns/variables of a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934965#M42012</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to run a macro on a set of columns (variables) of a dataset.&amp;nbsp; The macro is the following:&amp;nbsp;&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;%macro glm(dataset, y, x);
ods select OverallANOVA FitStatistics ParameterEstimates;
ods table ParameterEstimates=param_&amp;amp;y FitStatistics=fit_&amp;amp;y OverallANOVA=ANOVA_&amp;amp;y;


proc glm data=&amp;amp;dataset;
	class count;
    model &amp;amp;y. = &amp;amp;x. /solution;
quit;

%mend;

%glm(TSM_Mods, n_Mod1_PS, count);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro now runs on the column n_Mod1_PS but it has to run on&amp;nbsp;&amp;nbsp;n_Mod2_PS, ....,&amp;nbsp;n_Mod99_PS then on&amp;nbsp;n_Mod1_CV,&amp;nbsp;n_Mod2_CV, ....,&amp;nbsp;n_Mod99_CV then on&amp;nbsp;n_Mod1_INF,&amp;nbsp;n_Mod2_INF, ....,&amp;nbsp;n_Mod99_INF. How can I modify %glm(TSM_Mods,..., count) line to run the macro on all the variables I listed here that are present in the dataset TSM_Mods?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 13:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934965#M42012</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-07-08T13:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Run a macro on a set of columns/variables of a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934966#M42013</link>
      <description>&lt;P&gt;Something like this should do the job:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SetWithVariablesNames;
input variableName $ 32.;
cards;
n_Mod1_PS 
n_Mod2_PS
...
n_Mod99_PS
n_Mod1_CV 
n_Mod2_CV
...
n_Mod99_CV 
n_Mod1_INF
n_Mod2_INF
...
n_Mod99_INF
;
run;

data _null_;
  set SetWithVariablesNames;
  call execute('%nrstr(%glm(TSM_Mods, ' !! variableName !! ', count))');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming the data sets with your variables exists you can use the following PROC TRANSPOSE trick to get list of selected variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose 
  data = TSM_Mods(obs=0 keep=n_Mod:) /* &amp;lt;--- select variables you need */
  out = SetWithVariablesNames(rename=(_name_=variableName));
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 14:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934966#M42013</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-07-08T14:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Run a macro on a set of columns/variables of a dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934968#M42014</link>
      <description>&lt;P&gt;To answer your specific question about how to use macros for this problem, see here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-many-files/m-p/934673#M42004" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-many-files/m-p/934673#M42004&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;shows that running many regressions does not require a macro at all&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html#:~:text=One%20way%20to%20run%201000,%2C%20NumVars)%3B%20.." target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html#:~:text=One%20way%20to%20run%201000,%2C%20NumVars)%3B%20..&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which brings up a bigger point: what are you going to do with all of these regressions once you run them? Have you even thought about that? I assume you have, but really, running hundreds of regressions is a poor approach. Running something like a Partial Least Squares (PROC PLS) model, with all the variables in the model at once, seems like it might be a better approach, and its a hell of a lot faster and much much easier to program. Please see &lt;A href="https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/pls.pdf" target="_self"&gt;this paper&lt;/A&gt; by Randy Tobias of SAS Institute about PLS, where he fits a PLS model to 1,000 X variables (all in the model at once) and gets a useful result. Also see &lt;A href="https://community.jmp.com/kvoqx44227/attachments/kvoqx44227/learn-jmp-tutorials-tkb/45/4/PLSBartell%20Jan%202019.pdf" target="_self"&gt;this paper&lt;/A&gt; about PLS by Bartell (who works for JMP).&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2024 14:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Run-a-macro-on-a-set-of-columns-variables-of-a-dataset/m-p/934968#M42014</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-08T14:58:13Z</dc:date>
    </item>
  </channel>
</rss>

