DATA Step, Macro, Functions and more

How to interpolate data

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

How to interpolate data

Hi all,

I have a dataset (see below) that contains interest rate for 1, 2, 3, 5, 7 and 10 year securities. I'd like to interpolate the rates to gather the rates for 4, 6, 8, and 9 years. I looked up the PROC EXPAND procedure but am not quite sure if it's appropriate to use it in my case.

Time Periodtenyrsevenyrfiveyrthreeyrtwoyroneyr
19767.617.427.186.776.315.88
19777.427.236.996.686.456.08
19788.418.368.328.298.338.34
19799.439.479.519.710.1110.65
198011.4311.411.4511.5111.7312
198113.9214.0714.2514.4614.5714.8
198213.0113.0613.0112.9312.812.27
198311.111.0210.7910.4510.219.58
198412.4612.4212.2611.9211.6710.91
198510.6210.510.129.649.278.42
19867.677.547.37.066.866.45

Thank you very much for your suggestions!

Sabrina


Accepted Solutions
Solution
‎04-22-2014 02:46 PM
Respected Advisor
Posts: 4,641

Re: How to interpolate data

Or better, fit a spline:

data want2;

array ot{10} oneyr twoyr threeyr fouryr fiveyr sixyr sevenyr eithtyr nineyr tenyr;

set have;

do i = 4, 6, 8, 9;

  ot{i} = msplint(i, 6, 1,2,3,5,7,10,oneyr, twoyr, threeyr, fiveyr, sevenyr, tenyr);

  end;

drop i;

run;

PG

PG

View solution in original post


All Replies
Respected Advisor
Posts: 4,641

Re: How to interpolate data

Use the direct approach for linear interpolation:

data have;

input Time_Period tenyr sevenyr fiveyr threeyr twoyr oneyr;

datalines;

1976 7.61 7.42 7.18 6.77 6.31 5.88

1977 7.42 7.23 6.99 6.68 6.45 6.08

1978 8.41 8.36 8.32 8.29 8.33 8.34

1979 9.43 9.47 9.51 9.7 10.11 10.65

1980 11.43 11.4 11.45 11.51 11.73 12

1981 13.92 14.07 14.25 14.46 14.57 14.8

1982 13.01 13.06 13.01 12.93 12.8 12.27

1983 11.1 11.02 10.79 10.45 10.21 9.58

1984 12.46 12.42 12.26 11.92 11.67 10.91

1985 10.62 10.5 10.12 9.64 9.27 8.42

1986 7.67 7.54 7.3 7.06 6.86 6.45

;

data want;

array ot{10} oneyr twoyr threeyr fouryr fiveyr sixyr sevenyr eithtyr nineyr tenyr;

set have;

ot{4} = 0.5 * (ot{3} + ot{5});

ot{6} = 0.5 * (ot{5} + ot{7});

ot{8} = (2*ot{7} + ot{10})/3;

ot{9} = (ot{7} + 2*ot{10})/3;

run;

PG

PG
Super User
Posts: 17,750

Re: How to interpolate data

Can switch the data to a different format (see below) and then run a linear regression if you wanted.

You can use the estimate output to get the interpolated values by including the years you want in the dataset but leave the rate empty.

timeperiod year rate

1976 1 5.88

1976 2 6.31

1976 3 6.77

1976 4 .

Occasional Contributor
Posts: 9

Re: How to interpolate data

Thank you very much Reeza! That was my thought too! I was just curious if there was a more direct way to handle it. Have a great day!

Solution
‎04-22-2014 02:46 PM
Respected Advisor
Posts: 4,641

Re: How to interpolate data

Or better, fit a spline:

data want2;

array ot{10} oneyr twoyr threeyr fouryr fiveyr sixyr sevenyr eithtyr nineyr tenyr;

set have;

do i = 4, 6, 8, 9;

  ot{i} = msplint(i, 6, 1,2,3,5,7,10,oneyr, twoyr, threeyr, fiveyr, sevenyr, tenyr);

  end;

drop i;

run;

PG

PG
Occasional Contributor
Posts: 9

Re: How to interpolate data

Yes it works perfectly! Thanks a lot PG! I'll study more about this code and make sure I understand everything about a spline. Have a great day!

Super User
Posts: 9,671

Re: How to interpolate data

Or you can change it from wide to long, after that using proc expand.

data want2;

array ot{10} oneyr twoyr threeyr fouryr fiveyr sixyr sevenyr eithtyr nineyr tenyr;

set have;

do i =1 to 10;

  vname=vname(ot{i});value=ot{i};output;

  end;

drop i;

run;

Xia Keshan

Occasional Contributor
Posts: 9

Re: How to interpolate data

Yes that's right! Now I can try Proc Expand with itSmiley Happy Thank you very much and have a nice day!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 289 views
  • 8 likes
  • 4 in conversation