BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mspak
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@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
PaigeMiller
Diamond | Level 26

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
PaigeMiller
Diamond | Level 26

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
mspak
Quartz | Level 8

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

PaigeMiller
Diamond | Level 26

If I understand you properly, you need to have a

 

BY FIPS;

 

statement in PROC TRANSREG

--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 3307 views
  • 1 like
  • 2 in conversation