turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Linear interpolation

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2015 03:12 AM

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

Accepted Solutions

Solution

09-25-2015
06:23 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2015 02:47 PM

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2015 08:05 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2015 09:35 AM - edited 09-15-2015 09:36 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-15-2015 02:47 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-17-2015 08:19 AM - edited 09-17-2015 08:20 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-17-2015 11:32 AM

If I understand you properly, you need to have a

BY FIPS;

statement in PROC TRANSREG