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;
Example: https://documentation.sas.com/doc/en/statug/15.2/statug_reg_gettingstarted02.htm
Thank you,
HHC
@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).
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.
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.