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!!

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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