Search code examples
rsasregression

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.


Solution

  • 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;