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!!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.