Help using Base SAS procedures

linear interpolation of missing data

Reply
Frequent Contributor
Posts: 75

linear interpolation of missing data

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              

PROC Star
Posts: 7,480

Re: linear interpolation of missing data

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;

Frequent Contributor
Posts: 75

Re: linear interpolation of missing data

I only have sas 9.2 it did not work.

PROC Star
Posts: 7,480

Re: linear interpolation of missing data

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

PROC Star
Posts: 7,480

Re: linear interpolation of missing data

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

Frequent Contributor
Posts: 75

Re: linear interpolation of missing data

Thank you.

Super Contributor
Posts: 543

Re: linear interpolation of missing data

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!

Frequent Contributor
Posts: 75

Re: linear interpolation of missing data

Posted in reply to AncaTilea

Thanks!!

Ask a Question
Discussion stats
  • 7 replies
  • 2105 views
  • 6 likes
  • 3 in conversation