Obsidian | Level 7

## Bilinear interpolation in SAS

Is it possible to do bilinear interpolation in SAS?

For interpolation in one dimension I found that this can be easily done using the "proc expand" or a "proc transreg" (link: https://support.sas.com/kb/24/560.html).

However, for the case where I have 2 "input variables (x,y)" and one "output variable (z)" I have not found a good procedure.

Are there any good procedures to do bilinear interpolation in SAS?

Additional clarification on what I mean with "bilinear interpolation"

With bilinear I am aiming to the meaning that it has on WikiPedia (https://en.wikipedia.org/wiki/Bilinear_interpolation). This means that I have a list of (x,y,z) values, and that I am looking for some function that can fill in the missing z-values if I provide the missing z-values if I provide a list of (x,y) values within the range of the original provided values.

Interpolation methods that would be a great fit for my purpose:

Although the latter one I personally do not prefer, it could also provide a solution to my problem.

Examples from other programming languages

Examples of the function I am looking for can also be found in other programming languages. All the examples accept a list of (X, Y, Z) values, together with a list of (X0, Y0) values for which the (Z) values are then determined so these can be added to a table.

24 REPLIES 24
Super User

## Re: Bilinear interpolation in SAS

Is a regression model an option?

PROC GLM?

Or RSREG?

Obsidian | Level 7

## Re: Bilinear interpolation in SAS

Hi Reeza,

Thank you for the suggestion! My personal drawback on this, is that I have a list of numbers (x, y, z) which we know to be exact. The goal is to estimate the z value for a new point (x,y). The function should pass trough the original numbers (x, y, z), as they are exact, and interpolate these number linearly (or in a smoothed way).
Opal | Level 21

## Re: Bilinear interpolation in SAS

If you have licence for SAS/GRAPH, look at the G3GRID procedure. It does linear, spline and smooth interpolations over a grid.

PG
Diamond | Level 26

## Re: Bilinear interpolation in SAS

I guess this all depends on the meaning of "bilinear", which wasn't specified in the original question, but my guessing is that splines are not "bilinear". Linear regression with 2 Xs (and only the linear terms) is what I think "bilinear" means.

--
Paige Miller
Obsidian | Level 7

## Re: Bilinear interpolation in SAS

Hi PaigeMiller,

With bilinear I am aiming to the meaning that it has on WikiPedia (https://en.wikipedia.org/wiki/Bilinear_interpolation). This means that I have a list of (x,y,z) values, and that I am looking for some function that can fill in the missing z-values if I provide the missing z-values if I provide a list of (x,y) values within the range of the original provided values.

Thank you for the advice, I will adjust my question to avoid all unclarities.

Obsidian | Level 7

## Re: Bilinear interpolation in SAS

Hi PGStats,

I indeed saw the G3GRID procedure in my search, and this is in our licence.

However after reading the documentation I only found examples to make graphs. My goal is to add the z-value to a table of (x,y) values. Where the z-value is determined by an interpolation of a given (x, y, z) table. I am not sure if the G3GRID procedure can do this?
Opal | Level 21

## Re: Bilinear interpolation in SAS

To quote the documentation for proc G3GRID:

The G3GRID procedure does not produce graphics output. PROC G3GRID produces an output data set that you can use as the input data set for PROC G3D or PROC GCONTOUR.

PG
Obsidian | Level 7

## Re: Bilinear interpolation in SAS

Just to clarify on what I mean with bilinear.

With bilinear I am aiming to the meaning that it has on WikiPedia (https://en.wikipedia.org/wiki/Bilinear_interpolation). This means that I have a list of (x,y,z) values, and that I am looking for some function that can fill in the missing z-values if I provide the missing z-values if I provide a list of (x,y) values within the range of the original provided values.
Diamond | Level 26

## Re: Bilinear interpolation in SAS

PROC GLM will do this. It also allows for the prediction/interpolation of values of z for different values of (x,y) that were not used to build the model.

--
Paige Miller
Super User

## Re: Bilinear interpolation in SAS

It seems like imputing MISSING value.

Did you check PROC MI ?

Calling @Rick_SAS

SAS Super FREQ

## Re: Bilinear interpolation in SAS

IMHO, you should fit a parametric model (PROC RSREG) or a nonparametric model (PROC LOESS) to the data. If these are spatial data, then there are specialized routines (such as PROC KRIGE) that you can use to model the response.

Diamond | Level 26

## Re: Bilinear interpolation in SAS

I don't get the suggestion of LOESS or RSREG, the question specifically asks for linear interpolation.

--
Paige Miller
SAS Super FREQ

## Re: Bilinear interpolation in SAS

Yes, I am suggesting these as alternatives to the OP's request for linear interpolation. Also, my suggestions are smoothers; they do not necessarily pass through the data points.

The LOESS method has a SCORE statement that you can use to score new data:

``````data Grid;
call streaminit(12345);
do x = 0 to 10 by 2;
do y = 0 to 10 by 2;
z = abs(x-5) + abs(y-5) + round(rand("Normal"), 0.1);
output;
end;
end;
run;

data New;
do x = 1 to 9 by 2;
do y = 1 to 9 by 2;
output;
end;
end;

proc loess data=Grid plots(only)=contourfit;
model z = x y / degree=1;
score data=New / print;
ods exclude ScoreResults;
ods output ScoreResults = ScoreOut;
run;

proc print data=ScoreOut(obs=10);
run;``````
SAS Super FREQ

## Re: Bilinear interpolation in SAS

I just re-read the OP's comment that says

"I indeed saw the G3GRID procedure in my search, and this is in our license."

The first time I read it, I mistakenly thought the OP said that G3GRID wasn't licensed. If you have PROC G3GRID, it provides linear interpolation.

Discussion stats
• 24 replies
• 2066 views
• 8 likes
• 7 in conversation