DATA Step, Macro, Functions and more

Linear interpolation

Accepted Solution Solved
Reply
Regular Contributor
Posts: 162
Accepted Solution

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?

 

Thanks in advance.

 

Regards,

MSPAK

Attachment

Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Trusted Advisor
Posts: 1,614

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;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,614

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.

 

Trusted Advisor
Posts: 1,614

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.

Solution
‎09-25-2015 06:23 AM
Trusted Advisor
Posts: 1,614

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;
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:

 

proc summary nway data=z.adherent;
class fips fyear;
var adherent_county;
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;

 

data adherent;
set means all;
run;

 

proc sort data=adherent;
by fips fyear;
run;

 

proc transreg data=adherent(drop=_type_ _freq_);
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

Attachment
Trusted Advisor
Posts: 1,614

Re: Linear interpolation

If I understand you properly, you need to have a

 

BY FIPS;

 

statement in PROC TRANSREG

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 348 views
  • 1 like
  • 2 in conversation