## How to interpolate data

Solved
Occasional Contributor
Posts: 9

# 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 Period tenyr sevenyr fiveyr threeyr twoyr oneyr 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

Thank you very much for your suggestions!

Sabrina

Accepted Solutions
Solution
‎04-22-2014 02:46 PM
Posts: 5,523

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

All Replies
Posts: 5,523

## 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: 23,683

## 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
Posts: 5,523

## 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: 10,766

## 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 it Thank you very much and have a nice day!

🔒 This topic is solved and locked.