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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

8 REPLIES 8
Rajat183
Calcite | Level 5

This is very popular page but solution is good only for 1 variable

PeterClemmensen
Tourmaline | Level 20

Can you show us some example of what your data looks like?

ballardw
Super User

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.

Rajat183
Calcite | Level 5

This helped ..Thanks!

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Rajat183
Calcite | Level 5
I amusing fractional response model.Avoided that part just to keep the
things simple...Agree that it is not very prudent to check each possible
combination

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 452 views
  • 0 likes
  • 4 in conversation