Calcite | Level 5

how to generate predicted variable value using the new values of independent variable?

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;```  ```

5 REPLIES 5
PROC Star

Re: how to generate predicted variable value using the new values of independent variable?

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.

Super User

Re: how to generate predicted variable value using the new values of independent variable?

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;

Super User

Re: how to generate predicted variable value using the new values of independent variable?

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.

Opal | Level 21

Re: how to generate predicted variable value using the new values of independent variable?

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;
``````
PG
Ammonite | Level 13

Re: how to generate predicted variable value using the new values of independent variable?

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;

Discussion stats
• 5 replies
• 3588 views
• 0 likes
• 6 in conversation