Here I have the dataset and code like the following,
and since there is only 4 datapoints of x, the output table will contain only 4 prediced value of y.
What I want is the predicted values of y when x varies from 1 to 40, is that possible to generate the table in SAS? I know it's convenient to use the regression model to generate the results in EXCEL ,but I wonder if it's ok that I complete all of the steps in SAS.
THank you!!!
data a;
input x y;
cards;
1 0.992010835
2 0.966176685
3 0.955358056
4 0.941511026
;
run;
proc glm data= a;
model y= x;
output out= outa p=predy r=resid;
run;
Even if you were to make such predictions, they would never in any way be considered statistically valid. If X ranges from 1 to 4 in your modeling data set, you can only make predictions for X in the range of 1 to 4.
Not that your sample is likely good enough but use this input data set and look at the output data set.
data a; input x y; cards; 1 0.992010835 2 0.966176685 3 0.955358056 4 0.941511026 5 . 6 . 7 . 8 . 9 . 10 . 11 . 12 . 13 . 14 . 15 . 16 . 17 . 18 . 19 . 20 . 21 . 22 . 23 . 24 . 25 . 26 . 27 . 28 . 29 . 30 . 31 . 32 . 33 . 34 . 35 . 36 . 37 . 38 . 39 . 40 . ; run;
And place a QUIT; at the end of your Proc Glm;
The term you're looking for is 'score' a model.
You can do this several ways in SAS, partly depending on the PROC.
See the methods illustrated here.
As others have commented give your sample this isn't appropriate but I'm going to assume it was a mock up. At the end of the data, the validity is up to you.
A crude but simple method is with the CODE statement :
filename t temp;
proc glm data= a;
model y= x;
code file=t;
run;
quit;
data b;
do x = 1 to 40;
%include t;
output;
end;
run;
Hi,
With only one predictor below data step can be used for the predicted values.
data want;
do X=1 to 40;
predy=1.004343665 - 0.016231806*X;
output;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.