BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Antion
Calcite | Level 5
Hi,
I am computing mutliple simple linear regressions in the same procedure 'proc reg'.
The issue I have is that in the outest I have my 2 regressions with intercept, Rsq ... etc
BUT in the output dataset generated with 'output out=' statement (raw data), I can't have residuals for the first model And for the second model :

Is anyone can help on that ?

proc reg data = htwt outest=est1 rsquare;
eq1: model weight=height;
eq2: model weight=height age;
output out = htwt_2 r=res;
run;quit;


data htwt;
input sex $ age :3.1 height weight @@;
datalines;
f 143 56.3 85.0 f 155 62.3 105.0 f 153 63.3 108.0 f 161 59.0 92.0
f 191 62.5 112.5 f 171 62.5 112.0 f 185 59.0 104.0 f 142 56.5 69.0
f 160 62.0 94.5 f 140 53.8 68.5 f 139 61.5 104.0 f 178 61.5 103.5
f 157 64.5 123.5 f 149 58.3 93.0 f 143 51.3 50.5 f 145 58.8 89.0
m 164 66.5 112.0 m 189 65.0 114.0 m 164 61.5 140.0 m 167 62.0 107.5
m 151 59.3 87.0
;

/* data source */
http://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_reg_sect056....

Thanks !
1 ACCEPTED SOLUTION

Accepted Solutions
Paige
Quartz | Level 8
Sorting is unnecessary, as is the step containing RAW_ID = _N_;

Both output data sets are in the exact same sequence, and so you can simply do the merge without the BY statement here.

View solution in original post

5 REPLIES 5
Paige
Quartz | Level 8
Add an OUTPUT statement under EQ1
Antion
Calcite | Level 5
Ok,
Thank you, that makes almost the job.
This code outputs 2 datasets that contains the intial data and the residual column.

The thing is that I am not able to output in the same dataset !
If i try to output in the same dataset i got an error : "ERROR: Data set WORK.HTWT_1 is already open for output."

proc reg data = htwt outest=est1 rsquare;
eq1: model weight=height;
output out = htwt_1 r=res1;
eq2: model weight=height age;
output out = htwt_2 r=res2;
run;quit;

Regards,
Antoine
Paige
Quartz | Level 8
> The thing is that I am not able to output in the same
> dataset !

I don't think this is possible from PROC REG.

If only SAS provided a way to MERGE data sets! That would solve the problem! Message was edited by: Paige
Antion
Calcite | Level 5
My conclusion is that with proc REG I MUST ouptput in different datasets to get residuals from different models !
(I don't know if the output logic is different in proc glm or other regression procedure)

So I have a solution but which is probably not optimal :

/* add a raw id to my input data */
data Htwt;
set Htwt;
RAW_ID = _N_;
run;

/* run my 2 regressions and output residuals */
proc reg data = htwt outest=est1 rsquare;
eq1: model weight=height;
output out = htwt_1 r=res1;
eq2: model weight=height age;
output out = htwt_2 r=res2;
run;quit;

/* merge back together residuals */
proc sort data = htwt_1; by RAW_ID; run;
proc sort data = htwt_2; by RAW_ID; run;
data htwt_1_2(drop = RAW_ID);
merge htwt_1 htwt_2;
by raw_id;
run;

At the end it may be same processing time than running two time the PROC REG :
proc reg data = htwt outest=est1 rsquare;
eq1: model weight=height;
output out = htwt_out r=res1;
run;quit;
proc reg data = htwt_out outest=est1 rsquare;
eq2: model weight=height age;
output out = htwt_out r=res2;
run;quit;

Regards,
Paige
Quartz | Level 8
Sorting is unnecessary, as is the step containing RAW_ID = _N_;

Both output data sets are in the exact same sequence, and so you can simply do the merge without the BY statement here.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 6906 views
  • 0 likes
  • 2 in conversation