BookmarkSubscribeRSS Feed
thdang
Calcite | Level 5

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              

7 REPLIES 7
art297
Opal | Level 21

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;

thdang
Calcite | Level 5

I only have sas 9.2 it did not work.

art297
Opal | Level 21

It should have worked (I think) in 9.2, but you would have to have licensed SAS/ETS.

art297
Opal | Level 21

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

thdang
Calcite | Level 5

Thank you.

AncaTilea
Pyrite | Level 9

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!

thdang
Calcite | Level 5

Thanks!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 4669 views
  • 6 likes
  • 3 in conversation