Hi,
I would like to store the residuals and predicted values from my proc reg into a dataset. Unfortunately, so far I have only been able to print them onto my log. Below is the code I am using and I feel that I am missing smth very obvious; my dataset is attached. Could you please give me your thoughts?
dm 'log;clear;output;clear;';
proc reg data = Mydataset;
model y = var1 var2 var3 var4 var5/p;
output out = fitdata p=pred r=residual;
run; quit;
What does your LOG show when you run that Proc Reg? Does is show the data set Fitdata as created?
Example when I run this submitted code (which you test as you should have the SASHELP.CLASS data set)
proc reg data=sashelp.class; model weight= age height; output out=fitdata p=pred r=residual; run; quit;
My log shows:
6 proc reg data=sashelp.class; NOTE: Writing HTML Body file: sashtml.htm 7 model weight= age height; 8 output out=fitdata p=pred r=residual; 9 run; 10 quit; NOTE: The data set WORK.FITDATA has 19 observations and 7 variables. NOTE: PROCEDURE REG used (Total process time): real time 0.64 seconds cpu time 0.35 seconds
The first note tells the the set Fitdata was actually created. Opening the data set, or printing it, will show that the original data from the Sashelp.Class data set has two variables added: Pred and Residual.
If you expect something else you are not communicating the expectation very well.
Suggestion: when naming the output variables for something like this it is a good idea to make the name a bit clearer as to which variable has been predicted or the residual is from. You might use the output of this step as input into another and either accidentally overwrite the variables with different pred residual or lose track as to what they represent. So names like Ypred or Yresid are an idea to consider.
Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
been able to print them onto my log. Below is the code I am using and I feel that I am missing smth very obvious
What do you see when you try to print a few rows of the output data set?
proc print data=fitdata(obs=10);
var y pred residual;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.