aehie
aehie

Reputation: 178

How to include all the dataset variables into the model

I am wondering, if SAS can include all the dataset variables into a regression model without typing them all. I used R before, and I want something like:

model <- lm(y ~ ., data = d)

but in SAS.

Upvotes: 3

Views: 3679

Answers (2)

Sundar Krishnan
Sundar Krishnan

Reputation: 43

Here is one more way, but I have not tried it.

proc reg data=d;
model y = _all_;
run;

Since regression model by default can be built using only numeric variables you can use this.

proc reg data=d;
model y = _num_;
run;

If you have a character variable, convert it to a Weight of Evidence transformed variable so that they will be converted to numeric and then you can use the above code.

Upvotes: 0

DWal
DWal

Reputation: 2762

As far as I know, SAS doesn't have an simple way to do this.

You could put all of your independent variables into a macro variable then reference the macro variable in your model statement:

proc sql;
select name into :ivars separated by ' '
from dictionary.columns
where libname eq 'WORK'      /*library name        */
  and memname eq 'YOURDATA'  /*data set name       */
  and name    ne 'DEPVAR'    /*exlude dep variable */ ;
quit;

proc reg;
  model DEPVAR = &ivars;
run;

Upvotes: 9

Related Questions