## Linear interpolation

Solved
Regular Contributor
Posts: 162

# Linear interpolation

Dear all,

I have a dataset with the inherent ratio for years 1971, 1980, 1990, 2000 and 2010. I would like to interpolate the between values (for example, 1972 - 1979, 1981 - 1989, 1991 - 1999, 2001 - 2009, and 2011 - 2014) in my data.

Could anyone suggest a good solution for the linear interpolation?

Regards,

MSPAK

Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Posts: 2,989

## Re: Linear interpolation

So, I have peaked my own curiosity about doing this in PROC TRANSREG, and so here is a simple example, where I have averaged all of the data by FYEAR just to keep things simple.

``````proc summary nway data=one_two;
class fyear;
var inherent;
output out=means mean=;
run;
data augment;
do fyear=1971 to 2010 by 1;
output;
end;
run;
data means;
set means augment;
run;
proc transreg data=means(drop=_type_ _freq_);
model identity(inherent)=spline(fyear/knots=1971 1980 1990 2000 2010 degree=1);
output out=interpolation predicted residual;
run;``````
--
Paige Miller

All Replies
Posts: 2,989

## Re: Linear interpolation

mspak wrote:

Dear all,

I have a dataset with the inherent ratio for years 1971, 1980, 1990, 2000 and 2010. I would like to interpolate the between values (for example, 1972 - 1979, 1981 - 1989, 1991 - 1999, 2001 - 2009, and 2011 - 2014) in my data.

Could anyone suggest a good solution for the linear interpolation?

Linear interpolation can be performed in a SAS data step.

So, for example

interp=(y1-y0)*(year-prevyear)/(nextyear-prevyear);

where y1 is the inherent ratio of the next known year (1971, 1980, 1990, 2000 and 2010), y0 is the inherent ratio of the previous known year (1971, 1980, 1990, 2000 and 2010), and prevyear is the previous known year, and nextyear is the next known year.

Linear interpolation, with this data, will not work for 2011-2014.

--
Paige Miller
Posts: 2,989

## Re: Linear interpolation

[ Edited ]

I think you can also do linear interpolation in PROC TRANSREG where your KNOTS are the years 1971, 1980, 1990, 2000 and 2010, and the degree of the spline fit is 1.

BUT ... CAUTION ... I have never actually done this.

--
Paige Miller
Solution
‎09-25-2015 06:23 AM
Posts: 2,989

## Re: Linear interpolation

So, I have peaked my own curiosity about doing this in PROC TRANSREG, and so here is a simple example, where I have averaged all of the data by FYEAR just to keep things simple.

``````proc summary nway data=one_two;
class fyear;
var inherent;
output out=means mean=;
run;
data augment;
do fyear=1971 to 2010 by 1;
output;
end;
run;
data means;
set means augment;
run;
proc transreg data=means(drop=_type_ _freq_);
model identity(inherent)=spline(fyear/knots=1971 1980 1990 2000 2010 degree=1);
output out=interpolation predicted residual;
run;``````
--
Paige Miller
Regular Contributor
Posts: 162

## Re: Linear interpolation

[ Edited ]

Hi PaigeMiller,

I have a dataset with county-based and state-based adherent levels.  I tried to modify your program for my purpose. But I find somethign wrong the output. I would like to seek for your further advise. The following is the modified program:

class fips fyear;
output out=means mean=;
run;

data augment;
do fyear=1990 to 2010 by 1;
output;
end;
run;

PROC SORT DATA=MEANS OUT=FIPS (KEEP=FIPS) NODUPKEY;
BY FIPS;
RUN;

PROC SQL;
create table all as
select *
from augment, fips;
quit;

set means all;
run;

by fips fyear;
run;

model identity(adherent_county)= spline(fyear/knots=1990 2000 2010 degree=1);
output out=interpolation predicted residual;
run;

My purpose is to interpolate the adherent levels between 1990 to 2010 for each county. My next step is to perform the interpolation again for the state-based adherent level.

Hope to get any useful information.

Thank you.

MSPAK

Posts: 2,989

## Re: Linear interpolation

If I understand you properly, you need to have a

BY FIPS;

statement in PROC TRANSREG

--
Paige Miller
🔒 This topic is solved and locked.