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.
Is a regression model an option?
PROC GLM?
Or RSREG?
If you have licence for SAS/GRAPH, look at the G3GRID procedure. It does linear, spline and smooth interpolations over a grid.
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.
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.
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.
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.
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.
I don't get the suggestion of LOESS or RSREG, the question specifically asks for linear interpolation.
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;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.