Hallo, I have a timeserie but there are missing value at the beginning. How can I do a linear interpolation for those missing value? Thank you!
id date value


If you have SAS ETS you could use proc expand. e.g.:
data have;
informat date mmddyy10.;
format date mmddyy10.;
input id $ date value;
cards;
011080 3/31/1986 317.607
011080 4/30/1986 .
011080 5/30/1986 .
011080 6/30/1986 452.600
011080 7/31/1986 .
011080 8/29/1986 .
011080 9/30/1986 568.433
;
proc sort data=have;
by date;
run;
proc expand data=have out=LinInterp;
convert value=linear / method=join;
id date;
run;
I only have sas 9.2 it did not work.
It should have worked (I think) in 9.2, but you would have to have licensed SAS/ETS.
Rick's blog provides links for accomplishing the task at least 3 different ways, ETS, IML and a data step. If you don't have either ETS or IML licensed, you should be able to incorporate the datastep solution. see: Linear interpolation in SAS - The DO Loop
Thank you.
Hi.
If you want to "linearly" impute the data then you can do a proc reg on your data, save the linear equation, then calculate the missing values.
Something like this:
*using the data you have, I create "order" variable which is really just 1..n;
data have;
set have;
order = _n_;
run;
*run a linear regression to get the parameters for the line;
proc reg data = have;
model value = order;
ods output parameterEstimates = est(keep = variable estimate);
run;quit;
*save the intercept and the beta;
data _null_;
set est;
if variable = "Intercept" then do;
call symput ("int", estimate);
end;
if variable = "order" then do;
call symput ("beta", estimate);
end;
run;
data want;
set have;
if value = . then value = &int. + order * &beta.;
run;
Good luck!
Thanks!!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.