- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- 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
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.
- 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
- 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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- 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
- 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.