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

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
hhchenfx
Rhodochrosite | Level 12

Thank you,

HHC

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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