BookmarkSubscribeRSS Feed
NickVe
Obsidian | Level 7

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
Reeza
Super User

Is a regression model an option?

PROC GLM?

Or RSREG?

 

 

NickVe
Obsidian | Level 7
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).
PGStats
Opal | Level 21

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

PG
PaigeMiller
Diamond | Level 26

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
NickVe
Obsidian | Level 7

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.

NickVe
Obsidian | Level 7
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?
PGStats
Opal | Level 21

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

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
Ksharp
Super User

It seems like imputing MISSING value.

Did you check PROC MI ?

Calling @Rick_SAS

Rick_SAS
SAS Super FREQ

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.

 

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Rick_SAS
SAS Super FREQ

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;
Rick_SAS
SAS Super FREQ

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 24 replies
  • 1579 views
  • 8 likes
  • 7 in conversation