turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Looping SAS regreression for two variables

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

05-08-2018 02:49 PM

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

Accepted Solutions

Solution

05-08-2018
04:09 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rajat183

05-08-2018 03:15 PM - edited 05-08-2018 05:15 PM

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.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rajat183

05-08-2018 02:51 PM - edited 05-08-2018 02:52 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to draycut

05-08-2018 02:54 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rajat183

05-08-2018 03:06 PM

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

Solution

05-08-2018
04:09 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rajat183

05-08-2018 03:15 PM - edited 05-08-2018 05:15 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

05-08-2018 04:09 PM

This helped ..Thanks!

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

05-08-2018 06:35 PM

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

05-08-2018 07:04 PM

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

things simple...Agree that it is not very prudent to check each possible

combination

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rajat183

05-09-2018 06:49 AM

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

Paige Miller