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: Bilinear interpolation in SAS

Options

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

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

Posted 03-30-2020 11:55 AM
(2065 views)

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

*bilinear interpolation: https://en.wikipedia.org/wiki/Bilinear_interpolation**bicubic interpolation: https://en.wikipedia.org/wiki/Bicubic_interpolation**nearest-neighbours interpolation: https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation*

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

*MATLAB example (interp2): https://nl.mathworks.com/help/matlab/ref/interp2.html**Python example (interp2d): https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html**R example (interp2): https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/interp2**C++ example (libInterpolate): https://github.com/CD3/libInterpolate*

24 REPLIES 24

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

Is a regression model an option?

PROC GLM?

Or RSREG?

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

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

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

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

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

PG

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

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

Paige Miller

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

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.

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

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?

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?

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

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

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

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.

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.

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

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

Paige Miller

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

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

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

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

--

Paige Miller

Paige Miller

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

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

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

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.

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 16. Read more here about **why** you should contribute and **what is in it** for you!

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.