BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Barite | Level 11

Hi Everyone,

I have a timeseries and would like to run a polynomial regression of value on time and save the estimated value and error to a new file.

Can you please help?

Thank you,

HHC

/*THIS ONE WORK*/
proc datasets lib=work kill noprint;run;DM "log; clear; ";ods html close;ods html;

data test;
infile datalines missover;
input month Orders;
yearMonth = mod(month,12);
actual= not missing(orders);
datalines;

1 26156
2 32396
3 27415
4 24129
5 30350
6 21992
7 24705
8 36434
9 28858
10 37353
11 43137
12 52119
13 42119
14 42119
15 62119
16 72119
17 42119
18 62119
;

proc sgplot data=test;
reg x =month  y=orders /degree=10 clm;
title 'sgplot';

run;


proc glm data=test;
model orders = 
month 
month*month  
month*month*month  
month*month*month*month 
month*month*month*month*month
month*month*month*month*month*month
month*month*month*month*month*month*month
month*month*month*month*month*month*month*month
month*month*month*month*month*month*month*month*month
month*month*month*month*month*month*month*month*month*month
/ PREDICTED E;
output out=glm p=pred r=residual;
;
title 'GML regression';
run;
1 ACCEPTED SOLUTION
4 REPLIES 4
PaigeMiller
Diamond | Level 26

@hhchenfx says

 

/*THIS ONE WORK*/ proc glm data=test; model orders = month month*month month*month*month month*month*month*month month*month*month*month*month month*month*month*month*month*month month*month*month*month*month*month*month month*month*month*month*month*month*month*month month*month*month*month*month*month*month*month*month month*month*month*month*month*month*month*month*month*month / PREDICTED E;

 

It may work, meaning that the code doesn't have errors and produced output, but a 10th order polynomial fit to this data (or any other data that I know of) is completely inappropriate in the real world. You have most likely fit the noise of the data rather than finding a real signal, meaning that you have not really found a useful answer (you have found code that doesn't cause errors, that's all).

--
Paige Miller
WarrenKuhfeld
Ammonite | Level 13

As @PaigeMiller says, don't do that! If you want something more flexible than a cubic polynomial, use a cubic B-spline. Many of the linear modeling procedures such as transreg and glmselect can easily do it.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1148 views
  • 2 likes
  • 3 in conversation