BookmarkSubscribeRSS Feed
mesquitatorres
Calcite | Level 5

Hi,

 

I am trying to run a simple regression in base SAS that uses the orthogonal polynomial to the 7th degree and then append predictions to my data set. I do not have SAS IML so I cannot use this function. In R the code would simply be poly_model = lm(y ~ poly(x,n)) where 

y= { 8.249098 7.621568 7.199557 8.371507 7.927080 7.691783 7.662529 7.170472 7.562522 7.889212 8.139248
 7.695632 7.502941 7.914134 7.201237 7.963647 7.860750}

x={2001 2008 2016 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016}

n=7

 

This is how my data is structured in SAS:

data Model_data;

input Year Factor1 Factor2;

datalines;

2001    8.249098   .

2003    .                 8.371507

2004    .                 7.927080

2005    .                 7.691783

2006    .                 7.662529

2007    .                 7.170472

2008    7.621568   7.562522

2009    .                 7.889212

2010    .                 8.139248

2011    .                 7.695632

2012    .                 7.502941

2013    .                 7.914134

2014    .                 7.201237

2015    .                 7.963647

2016    7.199557   7.860750;

run;

 

I would like the output to be a datatable with variables Year Factor1 Factor2 Predictions.

 

I have tried running:

 

proc orthoreg data=model_data;
effect xMod = poly(Year1/ degree=7 details standardize(method= wmoments) standardize=center);
model Y = xMod;
run;

 

However, this did not yield the same results as the R code lm(y~poly(x,n)). I suspect this is because SAS centers and normalizes the data differently.

 

Any hints or help with this would be greatly appreciated. 

1 REPLY 1
Rick_SAS
SAS Super FREQ

I didn't check the options that you are using on the MODEL statement, but here is the DATA step that you should use to generate the data:

 

data Model_Data;
input x y;
datalines;
2001 8.249098 
2008 7.621568 
2016 7.199557 
2003 8.371507 
2004 7.92708 
2005 7.691783 
2006 7.662529 
2007 7.170472 
2008 7.562522 
2009 7.889212 
2010 8.139248 
2011 7.695632 
2012 7.502941 
2013 7.914134 
2014 7.201237 
2015 7.963647 
2016 7.86075 
;

For more about polynomials effects and the EFFECT statement, see "Construct polynomial effects in SAS regression models."

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 607 views
  • 0 likes
  • 2 in conversation