简体   繁体   English

SAS:如何将所有数据集变量包含到模型中

[英]SAS: 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. 我想知道,如果SAS可以将所有数据集变量都包含在回归模型中而无需全部输入。 I used R before, and I want something like: 我以前用过R,我想要的东西如下:

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

But in SAS. 但在SAS。 Thanks in advance! 提前致谢!

As far as I know, SAS doesn't have an simple way to do this. 据我所知,SAS没有一种简单的方法可以做到这一点。

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;

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 character variable, convert them to Weight of Evidence transformed variable so that they will be converted to numeric and then you can use the above code. 如果您有字符变量,请将它们转换为Evidence变换变量,以便它们转换为数字,然后您可以使用上面的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM