BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dim13
Obsidian | Level 7

Hello,

I am trying to estimate:

 

proc glm data=pros3; class tickers;

model clear=&va1 &va2 &va3 &va4/solution; output out=pros5 p=pred; run;

 

where the "va" variables are macro variables (characters) defined in a previous step (for example &va1 may insert the string "height*weight"  so that an interaction variable is included as an independent variable that estimates the product of variable height times weight - and includes it in the regression) 

 

although this is working fine I need to repeat this numerous times and I need to repeat this with with more variables.  I was trying to use

"model clear =&va1-&va4..........

but it does not allow me to.  Is there a different way to write consecutive, previously defined, macro-variables lists?  I know it would accept a list of variables that would read "ago1-ago10"  to include all variables from ago1 to ago10.  Can I do the same thing with my macro variables that are defined from &va1 to approximately &va100 ?

Thank you

Dimitrios

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The macro processor will not accept something like &va1-&va4 to mean &va1 &va2 &va3 &va4.

 

But if you are creating many &va macro variables in a previous data step, why not just concatenate them there as they are created, so now you have one long macro variable named &longmacrovariable. I can't be more specific since you really didn't show us this part of your program.

 

Alternatively, if you really must do it in PROC GLM (which I don't think you must, but like I said you didn't show us...)

 

%macro dothis;
proc glm data=xxxx;
class classvar;
model y = %do i=1 %to 100; &&va&i %end;/solution;
run; quit;
%mend dothis;
%dothis

Which brings up a different issue. I almost never think PROC GLM with 100 model terms is a sensible thing to do. Multi-collinearity is the problem. Better to use PROC PLS and/or PROC GLMSELECT instead of PROC GLM.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

The macro processor will not accept something like &va1-&va4 to mean &va1 &va2 &va3 &va4.

 

But if you are creating many &va macro variables in a previous data step, why not just concatenate them there as they are created, so now you have one long macro variable named &longmacrovariable. I can't be more specific since you really didn't show us this part of your program.

 

Alternatively, if you really must do it in PROC GLM (which I don't think you must, but like I said you didn't show us...)

 

%macro dothis;
proc glm data=xxxx;
class classvar;
model y = %do i=1 %to 100; &&va&i %end;/solution;
run; quit;
%mend dothis;
%dothis

Which brings up a different issue. I almost never think PROC GLM with 100 model terms is a sensible thing to do. Multi-collinearity is the problem. Better to use PROC PLS and/or PROC GLMSELECT instead of PROC GLM.

--
Paige Miller
Dim13
Obsidian | Level 7

Thank you very much for the solution, I will try this shortly.  With respect to the econometric issues that arise:  This is not related to an econometric approach, I understand that including a set of 100 variables is an issue especially in a loop where controlling the right hand side variables is more difficult.  It more of an exercise for me to figure out how to write the code so that I can later apply it to monte carlo and principal components.  Thank you though.  Will try

PaigeMiller
Diamond | Level 26

It more of an exercise for me to figure out how to write the code so that I can later apply it to monte carlo and principal components.

 

Okay, I understand your goals, but PROC PLS will produce better predictive models than principal components. PCA is not really a good tool for predictive modeling.

--
Paige Miller
Dim13
Obsidian | Level 7
Dear PaigeMiller,
thank you very much, your solution worked. As soon as the code runs will have to read up on the actual methods I need to employ. Will consider what you suggested on proc pls once I get up to speed on the theory part. Thanks again,
Best
Dimitrios
PaigeMiller
Diamond | Level 26

Here is a useful document on Partial Least Squares

http://support.sas.com/rnd/app/stat/papers/pls.pdf

 

I can it useful because it explains the statistical analysis performed. It is not useful for the examples of code, as it refers to an old version of PROC PLS, the syntax has changed greatly. So just read the description of Partial Least Squares, ignore the code.

--
Paige Miller
Reeza
Super User
I would generate my variable lists, using combinations/permutation functions in a data step and call them via call execute. If you're looking at optimal ways to code this in real life.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 861 views
  • 5 likes
  • 3 in conversation