变量中具有特定参数的 SAS 回归
SAS Regression with Specific Parameters in the Variables
下午好。
是否可以对变量进行回归,比如 Y = X1 (Between Q1 and Q3) X2 (X2 > 100) X3?我不希望回归 X1 或 X2 中的所有数据,只回归我确定的参数中的数据。
如何回归分位数 Q3 和 Q4 之间的所有变量?
我的处理方式是否正确?
感谢您的支持。
*Regression output;
ods graphics on;
proc reg data=mydata PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
title 'Working Regression Model';
run;
ods graphics off;
如果您只想使用部分数据进行回归,您可以在 proc reg
本身中将其过滤掉:
proc reg data=mydata (where=(X1 Between Q1 and Q3 and X2 > 100))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
也就是说,如果 Q1
和 Q3
是 myData
中的字段。如果没有,您可以为它们创建宏变量。例如
%let Q1 = 50;
%let Q3 = 250;
proc reg data=mydata (where=(X1 Between &Q1. and &Q3. and X2 > 100))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
如果您预先知道 Q1 和 Q3。
如果 Q1
和 Q3
是另一个数据集中的字段,proc sql
和 select Q1, Q3. into :Q1, :Q3
或数据步骤 call symput('Q1', Q1); call symput('Q3', Q3);
可以完成这项工作。
阅读您的评论后编辑解释 Q1
等是分位数:
以下示例可能包含您需要的所有构建块
ods graphics on;
proc means data=SASHELP.CLASS noprint;
var Height Weight;
output out=CLASS_Q
P25(Height Weight)=Height_Q1 Weight_Q1
P75(Height Weight)=Height_Q3 Weight_Q3;
run;
data _NULL_;
set CLASS_Q;
call symput('Height_Q1', Height_Q1);
call symput('Height_Q3', Height_Q3);
call symput('Weight_Q1', Weight_Q1);
call symput('Weight_Q3', Weight_Q3);
run;
%put _user_; *just to debug;
proc reg data=SASHELP.CLASS
(where=(Height Between &Height_Q1. and &Height_Q3. and Weight > &Weight_Q1.))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Age = Height Weight;
run;
下午好。
是否可以对变量进行回归,比如 Y = X1 (Between Q1 and Q3) X2 (X2 > 100) X3?我不希望回归 X1 或 X2 中的所有数据,只回归我确定的参数中的数据。
如何回归分位数 Q3 和 Q4 之间的所有变量?
我的处理方式是否正确?
感谢您的支持。
*Regression output;
ods graphics on;
proc reg data=mydata PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
title 'Working Regression Model';
run;
ods graphics off;
如果您只想使用部分数据进行回归,您可以在 proc reg
本身中将其过滤掉:
proc reg data=mydata (where=(X1 Between Q1 and Q3 and X2 > 100))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
也就是说,如果 Q1
和 Q3
是 myData
中的字段。如果没有,您可以为它们创建宏变量。例如
%let Q1 = 50;
%let Q3 = 250;
proc reg data=mydata (where=(X1 Between &Q1. and &Q3. and X2 > 100))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Y = X1 X2 X3;
如果您预先知道 Q1 和 Q3。
如果 Q1
和 Q3
是另一个数据集中的字段,proc sql
和 select Q1, Q3. into :Q1, :Q3
或数据步骤 call symput('Q1', Q1); call symput('Q3', Q3);
可以完成这项工作。
阅读您的评论后编辑解释 Q1
等是分位数:
以下示例可能包含您需要的所有构建块
ods graphics on;
proc means data=SASHELP.CLASS noprint;
var Height Weight;
output out=CLASS_Q
P25(Height Weight)=Height_Q1 Weight_Q1
P75(Height Weight)=Height_Q3 Weight_Q3;
run;
data _NULL_;
set CLASS_Q;
call symput('Height_Q1', Height_Q1);
call symput('Height_Q3', Height_Q3);
call symput('Weight_Q1', Weight_Q1);
call symput('Weight_Q3', Weight_Q3);
run;
%put _user_; *just to debug;
proc reg data=SASHELP.CLASS
(where=(Height Between &Height_Q1. and &Height_Q3. and Weight > &Weight_Q1.))
PLOTS(ONLY)=(DIAGNOSTICS FITPLOT RESIDUALS);
model Age = Height Weight;
run;