<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Bilinear interpolation in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/640078#M190553</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/283816"&gt;@NickVe&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be to perform &lt;EM&gt;linear&lt;/EM&gt; interpolation &lt;EM&gt;twice&lt;/EM&gt; (once in x-direction, then in y-direction or vice versa) using one of the two procedures suggested in the SAS Usage Note you linked to. I think PROC EXPAND would be superior for this approach, but I don't have a SAS/ETS license, so I use PROC TRANSREG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But first a DATA step approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create example data
     HAVE1: rectangular x-y grid with known values z=f(x,y)
     HAVE2: random points (x,y) in the interior of the grid
*/

%let xmesh=0.5;
%let ymesh=1.25;
%let xmin=1;
%let xmax=4;
%let ymin=0;
%let ymax=5;

data have1;
do x=&amp;amp;xmin to &amp;amp;xmax by &amp;amp;xmesh;
  do y=&amp;amp;ymin to &amp;amp;ymax by &amp;amp;ymesh;
    z=10*sin((x**2-1.618*x*y+3.142*y**2-40)/10);
    output;
  end;
end;
run;

data have2;
call streaminit(27182818);
do _n_=1 to 100;
  x=rand('uniform',&amp;amp;xmin, &amp;amp;xmax);
  y=rand('uniform',&amp;amp;ymin, &amp;amp;ymax);
  output;
end;
run;

/* Bilinear interpolation in a DATA step (and a preliminary PROC SQL step) */

proc sql;
create view vhave2 as
select x, y, floor(x/&amp;amp;xmesh)*&amp;amp;xmesh as x1,
             floor(y/&amp;amp;ymesh)*&amp;amp;ymesh as y1
from have2
order by x1, y1, x, y;
quit;

data want(keep=x y z);
if _n_=1 then do;
  dcl hash h(multidata:'y');
  h.definekey('x1','y1');
  h.definedata('f');
  h.definedone();
  call missing(x1,y1,f);
  do until(lr);
    set have1 end=lr;
    if x&amp;lt;&amp;amp;xmax &amp;amp; y&amp;lt;&amp;amp;ymax then h.add(key:x,        key:y,        data:z);
    if x&amp;lt;&amp;amp;xmax &amp;amp; y&amp;gt;&amp;amp;ymin then h.add(key:x,        key:y-&amp;amp;ymesh, data:z);
    if x&amp;gt;&amp;amp;xmin &amp;amp; y&amp;lt;&amp;amp;ymax then h.add(key:x-&amp;amp;xmesh, key:y,        data:z);
    if x&amp;gt;&amp;amp;xmin &amp;amp; y&amp;gt;&amp;amp;ymin then h.add(key:x-&amp;amp;xmesh, key:y-&amp;amp;ymesh, data:z);
  end;
end;
set vhave2;
by x1 y1;
if first.y1 then do;
  rc=h.find();
  if rc=0 then do;
    f11=f;
    h.find_next(); f12=f;
    h.find_next(); f21=f;
    h.find_next(); f22=f;
  end;
end;
if rc=0 then do;
  x2=x1+&amp;amp;xmesh;
  y2=y1+&amp;amp;ymesh;
  z = (f11*x2*y2-f12*x2*y1-f21*x1*y2+f22*x1*y1
     -(f11   *y2-f12   *y1-f21   *y2+f22   *y1)*x
     -(f11*x2   -f12*x2   -f21*x1   +f22*x1   )  *y
     +(f11      -f12      -f21      +f22      )*x*y)/&amp;amp;xmesh/&amp;amp;ymesh;
end;
else z=.;  
retain rc f:;  
run;

proc sort data=want;
by x y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The PROC SQL step assigns the (x,y) pairs to the lower left corner (x1,y1) of their [x1, x2)×[y1,y2) rectangle in the grid. (Note that this means a marginal limitation: No interpolation would be done for points in HAVE2 with x=&amp;amp;xmax or y=&amp;amp;ymax, if any.) For each of these (x1,y1) pairs the hash object contains the known values of the function at all four corners of the rectangle, f11=f(x1,y1), f12=f(x1,y2), f21=f(x2,y1) and f22=f(x2,y2). These are used in the formula (as per &lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_blank" rel="noopener"&gt;Wikipedia article&lt;/A&gt;) to compute the interpolated value z≈f(x,y). (Alternatively, PROC IML could be used, but I don't have a SAS/IML license.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: If dataset HAVE1 (the grid) is small and HAVE2 is large (millions of observations), the performance can be improved by omitting the preliminary PROC SQL step and not using BY-group processing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=x y z);
if _n_=1 then do;
  dcl hash h(multidata:'y');
  h.definekey('x1','y1');
  h.definedata('f');
  h.definedone();
  call missing(x1,y1,f);
  do until(lr);
    set have1 end=lr;
    if x&amp;lt;&amp;amp;xmax &amp;amp; y&amp;lt;&amp;amp;ymax then h.add(key:x,        key:y,        data:z);
    if x&amp;lt;&amp;amp;xmax &amp;amp; y&amp;gt;&amp;amp;ymin then h.add(key:x,        key:y-&amp;amp;ymesh, data:z);
    if x&amp;gt;&amp;amp;xmin &amp;amp; y&amp;lt;&amp;amp;ymax then h.add(key:x-&amp;amp;xmesh, key:y,        data:z);
    if x&amp;gt;&amp;amp;xmin &amp;amp; y&amp;gt;&amp;amp;ymin then h.add(key:x-&amp;amp;xmesh, key:y-&amp;amp;ymesh, data:z);
  end;
end;
set have2;
x1=floor(x/&amp;amp;xmesh)*&amp;amp;xmesh;
y1=floor(y/&amp;amp;ymesh)*&amp;amp;ymesh;
if h.find()=0 then do;
  f11=f;
  h.find_next(); f12=f;
  h.find_next(); f21=f;
  h.find_next(); f22=f;
  x2=x1+&amp;amp;xmesh;
  y2=y1+&amp;amp;ymesh;
  z = (f11*x2*y2-f12*x2*y1-f21*x1*y2+f22*x1*y1
     -(f11   *y2-f12   *y1-f21   *y2+f22   *y1)*x
     -(f11*x2   -f12*x2   -f21*x1   +f22*x1   )  *y
     +(f11      -f12      -f21      +f22      )*x*y)/&amp;amp;xmesh/&amp;amp;ymesh;
end;
else z=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this situation, the time saved by omitting the sort (ORDER BY clause) outweighs the time needed for many additional hash table lookups.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;--- End of EDIT ---&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As it turned out, the approach using PROC TRANSREG in two linear interpolations is prone to error, e.g., if data points fall on grid lines. The reason is that the NKNOTS= option of the MODEL statement of the second PROC TRANSREG step should ideally have individual values per BY group, which is impossible. The setting NKNOTS=0 (used in the draft code below) works for "generic" sets of points such as the random points in the above HAVE2 dataset, though. To mitigate the issues (and to reduce unnecessary calculations) more complex preparations of the input dataset would be needed. PROC EXPAND (SAS/ETS) is presumably more suitable for this approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the draft code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Bilinear interpolation via two linear interpolations with PROC TRANSREG (not recommended!) */

%let nyknots=%sysevalf((&amp;amp;ymax-&amp;amp;ymin)/&amp;amp;ymesh-1);

/* Prepare linear interpolation in y-direction */

proc sql;
create view have_y as
select x, y, z from have1
union
select floor(x/&amp;amp;xmesh)*&amp;amp;xmesh as x, y, . as z from have2
union
select ceil(x/&amp;amp;xmesh)*&amp;amp;xmesh as x, y, . as z from have2;
quit;

/* Perform linear interpolation in y-direction */

proc transreg data=have_y noprint;
by x;
model identity(z)=spline(y / degree=1 nknots=&amp;amp;nyknots);
output out=linintp_y(keep=x y pz rename=(pz=z)) predicted;
run;

/* Prepare linear interpolation in x-direction */

proc sql;
create view have_x as
select y, x, z from linintp_y
union
select y, x, . as z from have2;
quit;

/* Perform linear interpolation in x-direction */

proc transreg data=have_x noprint;
by y;
model identity(z)=spline(x / degree=1 nknots=0);  /* &amp;lt;--- CAUTION: nknots=0 can cause incorrect results, */
output out=linintp_x(keep=x y pz rename=(pz=z)) predicted;   /* e.g., if data points fall on grid lines! */
run;

/* Retrieve results of bilinear interpolation */

proc sql;
create table want2 as
select a.x, a.y, a.z
from linintp_x a, have2 b
where a.x=b.x &amp;amp; a.y=b.y
order by x, y;
quit;

/* Compare with results from DATA step approach */

proc compare data=want c=want2 criterion=1e-10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Apr 2020 10:31:23 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2020-04-16T10:31:23Z</dc:date>
    <item>
      <title>Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635863#M188844</link>
      <description>&lt;P&gt;Is it possible to do bilinear interpolation in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For interpolation in one dimension I found that this can be easily done using the "proc expand" or a "proc transreg" (link:&amp;nbsp;&lt;A href="https://support.sas.com/kb/24/560.html" target="_blank" rel="noopener"&gt;https://support.sas.com/kb/24/560.html&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, for the case where I have 2 "input variables (x,y)" and one "output variable (z)" I have not found a good procedure.&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Are there any good procedures to do bilinear interpolation in SAS?&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Additional clarification on what I mean with "bilinear interpolation"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;With bilinear I am aiming to the meaning that it has on WikiPedia (&lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_blank" rel="nofollow noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Bilinear_interpolation&lt;/A&gt;). 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.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Interpolation methods that would be a great fit for my purpose:&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;bilinear interpolation:&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_blank" rel="nofollow noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Bilinear_interpolation&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;bicubic interpolation:&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Bicubic_interpolation" target="_blank"&gt;https://en.wikipedia.org/wiki/Bicubic_interpolation&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;nearest-neighbours interpolation:&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation" target="_blank"&gt;https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;EM&gt;Although the latter one I personally do not prefer, it could also provide a solution to my problem.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Examples from other programming languages&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;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.&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;EM&gt;MATLAB example (interp2):&amp;nbsp;&lt;A href="https://nl.mathworks.com/help/matlab/ref/interp2.html" target="_blank"&gt;https://nl.mathworks.com/help/matlab/ref/interp2.html&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;Python example (interp2d):&amp;nbsp;&lt;A href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html" target="_blank"&gt;https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;R example (interp2):&amp;nbsp;&lt;A href="https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/interp2" target="_blank"&gt;https://www.rdocumentation.org/packages/pracma/versions/1.9.9/topics/interp2&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;LI&gt;&lt;EM&gt;C++ example (libInterpolate):&amp;nbsp;&lt;A href="https://github.com/CD3/libInterpolate" target="_blank"&gt;https://github.com/CD3/libInterpolate&lt;/A&gt;&lt;/EM&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 31 Mar 2020 05:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635863#M188844</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-03-31T05:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635864#M188845</link>
      <description>&lt;P&gt;Is a regression model an option?&lt;/P&gt;
&lt;P&gt;PROC GLM?&lt;/P&gt;
&lt;P&gt;Or RSREG?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 16:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635864#M188845</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-03-30T16:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635943#M188868</link>
      <description>&lt;P&gt;If you have licence for SAS/GRAPH, look at the G3GRID procedure. It does linear, spline and smooth interpolations over a grid.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 19:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635943#M188868</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-03-30T19:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635952#M188873</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2020 19:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/635952#M188873</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-30T19:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636077#M188903</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With bilinear I am aiming to the meaning that it has on WikiPedia (&lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_blank"&gt;https://en.wikipedia.org/wiki/Bilinear_interpolation&lt;/A&gt;). 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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the advice, I will adjust my question to avoid all unclarities.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 05:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636077#M188903</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-03-31T05:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636078#M188904</link>
      <description>Just to clarify on what I mean with bilinear.&lt;BR /&gt;&lt;BR /&gt;With bilinear I am aiming to the meaning that it has on WikiPedia (&lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_blank"&gt;https://en.wikipedia.org/wiki/Bilinear_interpolation&lt;/A&gt;). 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.</description>
      <pubDate>Tue, 31 Mar 2020 05:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636078#M188904</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-03-31T05:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636080#M188905</link>
      <description>Hi Reeza,&lt;BR /&gt;&lt;BR /&gt;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).</description>
      <pubDate>Tue, 31 Mar 2020 05:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636080#M188905</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-03-31T05:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636081#M188906</link>
      <description>Hi PGStats,&lt;BR /&gt;&lt;BR /&gt;I indeed saw the G3GRID procedure in my search, and this is in our licence.&lt;BR /&gt;&lt;BR /&gt;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?</description>
      <pubDate>Tue, 31 Mar 2020 05:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636081#M188906</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-03-31T05:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636153#M188947</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 10:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636153#M188947</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-31T10:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636168#M188959</link>
      <description>&lt;P&gt;It seems like imputing MISSING value.&lt;/P&gt;
&lt;P&gt;Did you check PROC MI ?&lt;/P&gt;
&lt;P&gt;Calling &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 11:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636168#M188959</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-31T11:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636173#M188961</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 11:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636173#M188961</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-03-31T11:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636184#M188967</link>
      <description>&lt;P&gt;I don't get the suggestion of LOESS or RSREG, the question specifically asks for linear interpolation.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 11:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636184#M188967</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-31T11:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636211#M188987</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The LOESS method has a SCORE statement that you can use to score new data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 12:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636211#M188987</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-03-31T12:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636295#M189018</link>
      <description>&lt;P&gt;To quote the documentation for proc G3GRID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;The G3GRID procedure does not produce &lt;SPAN class="ng-scope" data-gloss-modified="" data-gloss-item="1"&gt;&lt;A class="glossLink ng-scope" href="https://documentation.sas.com/" target="_blank"&gt;&lt;SPAN class="xisDoc-glossTerm ng-scope" data-gloss-term="1"&gt;graphics output&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;. PROC G3GRID produces an output data set that you can use as the input data set for PROC G3D or PROC GCONTOUR.&lt;/EM&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 31 Mar 2020 16:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636295#M189018</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-03-31T16:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636300#M189021</link>
      <description>&lt;P&gt;I just re-read the OP's comment that says&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;I indeed saw the G3GRID procedure in my search, and &lt;STRONG&gt;this is in our license&lt;/STRONG&gt;."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The first time I read it, I mistakenly thought the OP said that G3GRID &lt;STRONG&gt;wasn't&lt;/STRONG&gt;&amp;nbsp;licensed. If you have PROC G3GRID, it provides linear interpolation.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2020 17:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/636300#M189021</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-03-31T17:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639785#M190398</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the many responses. My hope was that there would be an easy method that constructed an interpolation(x, y) function (as is the case in the examples in Python, R, MATLAB and C++ shown in the original question). If I read the different responses correctly, this is not possible at all, am I correct with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The popular G3GRID method that is suggested does&amp;nbsp;&lt;EM&gt;not&lt;/EM&gt;&amp;nbsp;seem to meet my criteria. The reason is that I have irregularly spaced datapoints that I wish to determine. This appears to be impossible using this method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The MI method seems promising at first sight. However I only see examples where the imputation is done by either the "mean value" or by a "regression result". The documentation of this method does not discuss "interpolation".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current "quick and dirty" workaround is by using the "proc discrim" procedure, to essentially do 1-nearest neighbour interpolation. This gives me the value of the nearest point as the "interpolation". This is a workable solution at the moment for me, although it is far from ideal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a recap: I have a series of regularly spaced (x0, y0, z0) values. I also have a (very large) series of irregularly spaced (x, y) values for which I want to determine the corresponding z values.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 14:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639785#M190398</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-04-14T14:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639789#M190400</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/283816"&gt;@NickVe&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the many responses. My hope was that there would be an easy method that constructed an interpolation(x, y) function (as is the case in the examples in Python, R, MATLAB and C++ shown in the original question). If I read the different responses correctly, this is not possible at all, am I correct with this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC GLM does this. Which was mentioned earlier in this thread.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 14:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639789#M190400</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-14T14:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639799#M190401</link>
      <description>&lt;P&gt;&amp;gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;If I read the different responses correctly, this is not possible at all, am I correct with this?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I would not say that is a correct statement. It is possible by using programming statements. The difficulty seems to be that the built-in SAS procedures that we have suggested have been rejected by you for various reasons. If I remember correctly, you do not want a global (or even local) statistical fit but want a bilinear fit based on values at the corner of the cell (in a regular grid) in which each point lives.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've written about &lt;A href="https://blogs.sas.com/content/iml/2013/07/17/2d-binning.html" target="_self"&gt;how to use 2-D binning&lt;/A&gt; to find the cell that each point belongs to. If you are a programmer, such a routine can be programmed in the SAS/IML language by using &lt;A href="https://en.wikipedia.org/wiki/Bilinear_interpolation" target="_self"&gt;the definition of bilinear interpolation.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 15:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639799#M190401</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-04-14T15:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639990#M190485</link>
      <description>&lt;P&gt;If I read the documentation correctly, "proc GLM" only provides a "linear fit", not an "interpolation" as is asked in the original question. Please correct me if I misread this.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 06:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/639990#M190485</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-04-15T06:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Bilinear interpolation in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/640006#M190500</link>
      <description>&lt;P&gt;This 2D binning article looks indeed promosing workaround to generate a regular grid from my irregularly spaced data. This could then be combined with the G3GRID method proposed above. Note however that this is still a workaround and technically not a solution to my problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for rejecting the previous methods are that they do not answer the question:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;"proc GLM" provides a "fit", not an "interpolation" as requested&lt;/LI&gt;&lt;LI&gt;"RSREG" provides a "fit", not an "interpolation" as requested&lt;/LI&gt;&lt;LI&gt;G3GRID only works for "regular grids", not irregularily shaped data as requested&lt;/LI&gt;&lt;LI&gt;"PROC MI" seems only to do missing imputation, not "interpolation"&lt;/LI&gt;&lt;LI&gt;"PROC LOESS" provides a "fit", not an "interpolation" as requested&lt;/LI&gt;&lt;LI&gt;"PROC KRIGE" performs krigging, with is again a "fit", not an "interpolation" as requested&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The closest solution to my problem I have found seems to be the "proc discrim" method, which I use to make a 1NN interpolation. The advantage is that this meets the criteria of my question:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I can provide a "train" dataset of (X0, Y0, Z0) values&lt;/LI&gt;&lt;LI&gt;I can easily provide new values (X, Y) and obtain the corresponding (Z) values&lt;/LI&gt;&lt;LI&gt;This works for data that is &lt;EM&gt;not&lt;/EM&gt; on a rectangular grid&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;For me personally this is the most viable solution at the moment. Unfortunately this only fits the nearest point, and does not perform linear interpolation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that I could write my own program in SAS to solve this issue, however that was not the question. I wanted to avoid "re-inventing the wheel" by working with the optimized SAS procedures as much as possible. My belief was that these "interpolation functionalities" would also be available in SAS since they are available in for example MATLAB, R, Python and C++ (see examples).&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 07:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bilinear-interpolation-in-SAS/m-p/640006#M190500</guid>
      <dc:creator>NickVe</dc:creator>
      <dc:date>2020-04-15T07:23:30Z</dc:date>
    </item>
  </channel>
</rss>

