Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: Linear interpolation

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-15-2015 03:12 AM
(3306 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

If I understand you properly, you need to have a

BY FIPS;

statement in PROC TRANSREG

--

Paige Miller

Paige Miller

**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.

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.