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

Ok, I should explain the header better.

Let's say I have a data set like this:

 

PERMNO    DATE    Y     X1     X2      X3

A                   100     xx    xx      xx      xx

A                   100     xx    xx      xx      xx

A                   100     xx    xx      xx      xx

B                 ......

B

B

C

C

C

 

Basically, I want  to run multiple regression models. 

For example, Y ~ x1. Y~ x2, Y~X3, ...

In my real data set there are more than 10 variables.

 

I know that for a single model, I can run something like this:

proc reg data = have out = want;
    by permno date;
    model y = x1;
run;

But what shoud I do if I want to do a loop through my variables, so that I get all of models, y ~ x1, y~x2, y~x3 in one table. Can it possibly done in one proc reg, or should I define multiple ones and append them together?

 

I appreciate any help.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Transform your data and use by processing. Here is an example with sashelp.class:

 

data longClass;
set sashelp.class;
array a{*} age height;
do i = 1 to dim(a);
    var = vname(a{i});
    value = a{i};
    output;
    end;
drop i age height;
run;

proc sort data=longClass; by sex var; run;

proc reg data=longClass plots=none;
by sex var;
model weight = value;
run;
PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Transform your data and use by processing. Here is an example with sashelp.class:

 

data longClass;
set sashelp.class;
array a{*} age height;
do i = 1 to dim(a);
    var = vname(a{i});
    value = a{i};
    output;
    end;
drop i age height;
run;

proc sort data=longClass; by sex var; run;

proc reg data=longClass plots=none;
by sex var;
model weight = value;
run;
PG
Shayan2012
Quartz | Level 8
Thanks a lot, PGstats!

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!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3136 views
  • 2 likes
  • 2 in conversation