Hi,
I am running a regression where I need to pass two variables at a time and check all the combinations.
I have 10 macroeconomic variables and would like to run 45 (10C2) regression.Please suggest some solution by creating a long dataset so that I can leverage 'by' funcitionality and have all the results in one data set.
Thanks,
Rajat
Is something like this what you are looking for?
data junk; set sashelp.class; varlist= 'age height weight'; length firstvar secondvar $ 15; do i= 1 to (countw(varlist)-1); firstvar= scan(varlist,i); do j= (i+1) to countw(varlist); secondvar = scan(varlist,j); output; end; end; run; proc sort data=junk; by firstvar secondvar; run;
I used a somewhat smaller example set with 3 variables instead of 10.
If your actual variables have names longer than 15 character adjust the length statement to match your longest.
Remember that BY group processing can use more than a single variable, just like the sort.
This is very popular page but solution is good only for 1 variable
Can you show us some example of what your data looks like?
Is something like this what you are looking for?
data junk; set sashelp.class; varlist= 'age height weight'; length firstvar secondvar $ 15; do i= 1 to (countw(varlist)-1); firstvar= scan(varlist,i); do j= (i+1) to countw(varlist); secondvar = scan(varlist,j); output; end; end; run; proc sort data=junk; by firstvar secondvar; run;
I used a somewhat smaller example set with 3 variables instead of 10.
If your actual variables have names longer than 15 character adjust the length statement to match your longest.
Remember that BY group processing can use more than a single variable, just like the sort.
This helped ..Thanks!
Of course, just because you CAN get SAS to do these 45 regressions, that doesn't mean you SHOULD do it this way. There are better solutions than fitting the 45 different models. One of them is Partial Least Squares regression, which can handle all 10 variables in one model and not get badly influenced by collinearity between the variables.
I don't know what a fractional response model is, but any modelling that can be handled by regression can be handled by Partial Least Squares. As I said, PLS will usually fit the model better, and avoids these difficulties of looping throught 45 combinations of variables.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.