<?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: Finding Closest Value to a List of Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498719#M132608</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input x @@;
cards;
31 53 25 125 129 180
;

data t2;
input y @@;
cards;
31 62 93 124 155
;

proc sql;
create table want as
 select distinct *
  from t1,t2
   where x&amp;lt;=y
    group by x
	 having y=min(y);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Sep 2018 13:16:46 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-09-25T13:16:46Z</dc:date>
    <item>
      <title>Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498539#M132512</link>
      <description>&lt;P&gt;I have two tables&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 1&lt;/P&gt;&lt;P&gt;31&lt;/P&gt;&lt;P&gt;53&lt;/P&gt;&lt;P&gt;25&lt;/P&gt;&lt;P&gt;125&lt;/P&gt;&lt;P&gt;129&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 2&lt;/P&gt;&lt;P&gt;31&lt;/P&gt;&lt;P&gt;62&lt;/P&gt;&lt;P&gt;93&lt;/P&gt;&lt;P&gt;124&lt;/P&gt;&lt;P&gt;155&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want values on table 1 to be matched with the closest 'next' higher value from table 2.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired table&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input output&lt;/P&gt;&lt;P&gt;31&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;&lt;P&gt;53&amp;nbsp; &amp;nbsp; &amp;nbsp; 62&lt;/P&gt;&lt;P&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;&lt;P&gt;125&amp;nbsp; &amp;nbsp; 155&lt;/P&gt;&lt;P&gt;129&amp;nbsp; &amp;nbsp; 155&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498539#M132512</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-24T19:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498548#M132517</link>
      <description>&lt;P&gt;How big are these tables? For the size you have there, I'd be doing a temporary array but that loads it into memory so if it's a larger data set it may not work. Or if you need GROUP BY processing that approach won't work either.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235217"&gt;@Anirudh9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have two tables&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table 1&lt;/P&gt;
&lt;P&gt;31&lt;/P&gt;
&lt;P&gt;53&lt;/P&gt;
&lt;P&gt;25&lt;/P&gt;
&lt;P&gt;125&lt;/P&gt;
&lt;P&gt;129&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;table 2&lt;/P&gt;
&lt;P&gt;31&lt;/P&gt;
&lt;P&gt;62&lt;/P&gt;
&lt;P&gt;93&lt;/P&gt;
&lt;P&gt;124&lt;/P&gt;
&lt;P&gt;155&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want values on table 1 to be matched with the closest 'next' higher value from table 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input output&lt;/P&gt;
&lt;P&gt;31&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;
&lt;P&gt;53&amp;nbsp; &amp;nbsp; &amp;nbsp; 62&lt;/P&gt;
&lt;P&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;
&lt;P&gt;125&amp;nbsp; &amp;nbsp; 155&lt;/P&gt;
&lt;P&gt;129&amp;nbsp; &amp;nbsp; 155&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498548#M132517</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-24T19:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498551#M132518</link>
      <description>&lt;P&gt;Maybe 30-40 rows max.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498551#M132518</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-24T19:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498564#M132525</link>
      <description>&lt;P&gt;Here's one way then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input value1;
cards;
31
53
25
125
129
;

data t2;
input value2;
cards;
31
62
93
124
155
;
run;

data find_nearest;
*load data into temporary array;
array _nearest(5) _temporary_;

if _n_=1 then do j=1 to dim(_nearest);
    set T2;*dataset with values to load into array;
    _nearest(j) = value2;
end;

call sortn(of _nearest(*));

set T1;

do i=1 to dim(_nearest);
    if _nearest(i) &amp;gt; value1 then leave;
end;
nearest = _nearest(i);
Difference = _nearest(i) - value1;

keep value1 nearest difference;

run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 19:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498564#M132525</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-24T19:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498566#M132526</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
input var1 ;
cards;
31
53
25
125
129
;

data two;
input var2;
cards;
31
62
93
124
155
;
 
proc sql;
create table want(drop=a) as
select *, ifn(var2-var1&amp;lt;0,.,var2-var1) as a
from one, two
group by var1
having a=min(a);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 20:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498566#M132526</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-24T20:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498593#M132539</link>
      <description>&lt;P&gt;If you original data sets were both sorted, you could skip the proc sorts here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input value1;
cards;
31
53
25
125
129
;

data t2;
input value2;
cards;
31
62
93
124
155
;
run;

proc sort data=t1; by value1;run;
proc sort data=t2; by value2;run;

data want;
  set t1 (keep=value1 rename=(value1=value2)  in=in1)
      t2 (in=in2);
  by value2;
  if in1 then set t1;
  if in2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SAS behavior taken advantage of here is how and when the PDV (program data vector) gets assigned new values.&amp;nbsp; In the case of variables from t1 or t2, that only happens when there is a corresponding SET statement.&amp;nbsp; So VALUE1 (and all other T1 variables) is only updated when the "if in1 then set t1;" statement is executed.&amp;nbsp; That means that VALUE1 is NOT changed when a T2 record is read in.&amp;nbsp; The first SET statement&amp;nbsp; [set t1 ..... t2 (in=in2)] doesn't encounter value1 since it is renamed (for order purposes) to value2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This also means that if you have a T1 followed by multiple T2's, all those T2's would get the same (most recent) value1.&amp;nbsp; And if you have several consecutive T1 records, only the final one would propagate to subsequent T2's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As per comments elsewhere on this topic, the above does not accommodate keeping any T1 records for which value1 is higher than any available value2 in T2.&amp;nbsp; Here is a modification to include such records:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wantnew (drop=n2);
  set t1 (keep=value1 rename=(value1=value2)  in=in1)
      t2 (in=in2)
      nobs=nobs_both;
  by value2;
  if in1 then set t1 nobs=nobs1;
  else n2+1;
  if in2 or n2 &amp;gt;= nobs_both-nobs1;
  if in1 then call missing(value2);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 18:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498593#M132539</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-25T18:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498635#M132563</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;So&amp;nbsp;clever!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 03:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498635#M132563</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-25T03:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498689#M132591</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;: A creative solution indeed, but&amp;nbsp;does it solve the original question?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235217"&gt;@Anirudh9&lt;/a&gt;: Here are two other suggestions. Please note that I have inserted value 180 into the first dataset, just to demonstrate what happens if there is&amp;nbsp;&lt;EM&gt;no&lt;/EM&gt; higher (or equal) value contained in the second dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input x @@;
cards;
31 53 25 125 129 180
;

data t2;
input y @@;
cards;
31 62 93 124 155
;

/* Another PROC SQL solution */

proc sql;
create table want as
select x, (select min(y) from t2 where y&amp;gt;=x) as y
from t1;
quit;


/* Another DATA step solution */

proc sort data=t2;
by y;
run;

data want;
set t1;
do p=1 to n until(y&amp;gt;=x);
  set t2 point=p nobs=n;
end;
if y&amp;lt;x then y=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 10:24:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498689#M132591</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-25T10:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498719#M132608</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input x @@;
cards;
31 53 25 125 129 180
;

data t2;
input y @@;
cards;
31 62 93 124 155
;

proc sql;
create table want as
 select distinct *
  from t1,t2
   where x&amp;lt;=y
    group by x
	 having y=min(y);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 13:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498719#M132608</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-25T13:16:46Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498812#M132634</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;: A creative solution indeed, but&amp;nbsp;does it solve the original question?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The OP didn't specify what was wanted when there are value1's (variable X here) for which there are no next high value2's (variable Y).&amp;nbsp; So yes, while my solution worked for the sample data presented, it simply ignored case for X greater than the max Y value.&amp;nbsp; That may not be would the OP would want.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I don't think this mean one has to resort to the "&lt;EM&gt;&lt;STRONG&gt;do p&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token function"&gt;n&lt;/SPAN&gt; until&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;y&lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt;x&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;SPAN class="token punctuation"&gt;&lt;EM&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/EM&gt;" recommendation, which can be very expensive&amp;nbsp;when data sets are large, since it requires starting at the beginning of&amp;nbsp;data set 2 for every incoming record of data set 1 (although it eliminates the need to presort data set T1).&amp;nbsp; If avoiding sorts really was crucial, I'd go with a hash object technique, using data set T2 as the hash object.&amp;nbsp; &lt;SPAN class="token punctuation"&gt;I won't describe that approach here.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;Instead, assuming proc sort's are affordable, one could tweak my original suggestion (data wantold;) as per the below (see the data wantnew step).&amp;nbsp; I've already presorted T1 and T2 for this example.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input x @@;
cards;
25 31 53 125 129 180
;

data t2;
input y @@;
cards;
31 62 93 124 155
;


data wantold;
  set t1 (keep=x rename=(x=y)  in=in1)
      t2 (in=in2);
  by y;
  if in1 then set t1 nobs=nobs1;
  if in2;
run;


data wantnew (drop=n2);
  set t1 (keep=x rename=(x=y)  in=in1)
      t2 (in=in2)
      nobs=nobs_both;
  by y;
  if in1 then set t1 nobs=nobs1;
  else n2+1;
  if in2 or n2 &amp;gt;= nobs_both-nobs1;
  if in1 then call missing(y);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;The main difference above is to track how many T2 records have been read (variable N2) and compare that to the total number of T2 records available (NOBS_BOTH-NOBS1).&amp;nbsp; The data want_new step includes all records following the exhaustion T2.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;My main point in these suggestions is for sas programmers to realize that the PDV is their friend.&amp;nbsp; It's very useful to be aware of how and when (and what part of) the PDV is being modified throughout the data step.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 18:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498812#M132634</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-25T18:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498872#M132651</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;for your detailed reply.&amp;nbsp;Sorry for being unspecific and putting two answers into the same post. I wasn't referring to the special case ("180") which I introduced, but to the OP's own example:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235217"&gt;@Anirudh9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;I want values on table 1 to be matched with the closest 'next' higher value from table 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired table&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input output&lt;/P&gt;
&lt;P&gt;31&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;
&lt;P&gt;53&amp;nbsp; &amp;nbsp; &amp;nbsp; 62&lt;/P&gt;
&lt;P&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; 31&lt;/P&gt;
&lt;P&gt;125&amp;nbsp; &amp;nbsp; 155&lt;/P&gt;
&lt;P&gt;129&amp;nbsp; &amp;nbsp; 155&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, my understanding is that, e.g., value1=125 from (the OP's) "table 1" is to be matched with value2=155 from "table 2" -- the next higher value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run your code (original version), I obtain this dataset WANT:&lt;/P&gt;
&lt;PRE&gt;value2    value1

   31        31
   62        53
   93        53
  124        53
  155       129&lt;/PRE&gt;
&lt;P&gt;This differs significantly (i.e. not only in terms of row or column sort order) from the OP's "desired table". In particular, value1=125 doesn't occur at all. (Same with version WANTOLD. In WANTNEW only the correct assignment 180 --&amp;gt; &lt;STRONG&gt;.&lt;/STRONG&gt; is added.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did I overlook or misunderstand something? (I suppose so because the above discrepancy is too obvious.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I fully agree that the DO-loop approach I suggested would not be advisable for large tables. But I thought for datasets with "[m]&lt;SPAN&gt;aybe 30-40 rows max." (Anirudh9) it should&amp;nbsp;be acceptable in terms of run time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;&lt;SPAN class="token punctuation"&gt;My main point in these suggestions is for sas programmers to realize that the PDV is their friend.&amp;nbsp; It's very useful to be aware of how and when (and what part of) the PDV is being modified throughout the data step.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Very true! Much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 21:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/498872#M132651</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-09-25T21:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499078#M132751</link>
      <description>&lt;P&gt;Well, it took two commens from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;but I now see what he was pointing out.&amp;nbsp; I was ignoring instance of T1 records that were not immediately followed by a T2, yielding an interesting solution to a problem not posed by the OP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a correct version.&amp;nbsp; Like the others it also depends on asynchronous updating of the program data vector., reading from two sorted data sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input x @@;
cards;
25 31 53 125 129 180
;

data t2;
input y @@;
cards;
31 62 93 124 155
;


data want_correct;
  set t1;
  do while (y&amp;lt;x  and end_of_t2=0);
    set t2 end=end_of_t2;
  end;
  if y&amp;lt;x then call missing(y);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 13:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499078#M132751</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-26T13:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499091#M132753</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the same code on Python. Maybe you could help me translate the same to SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The match rate is what my target value is. actual_rate is table 1, matrix_rate is table 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the value In actual_rate is higher than max of matrix_rate, I want the highest value of matrix_rate to be used. I think this code will help understand my problem a lot better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;match_rate = []&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;actual_rate = [31,53,25,61,44,165,311,233]&amp;nbsp;&amp;nbsp;#These are samples, actual data is bigger, 30-40 rows&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;matrix_rate = [31,62,93,124,155,186,211,252,288]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;for i in range(np.size(actual_rate)):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;if actual_rate[i] &amp;gt; max(matrix_rate):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;match_rate[i] = max(matrix_rate)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;else:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;temp1 = []&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;for j in range(np.size(matrix_rate)):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;p = matrix_rate[j] - actual_rate[i]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (p &amp;gt;= 0):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp1.append(p)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;match_rate[i] = min(temp1) + actual_rate[I]&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 14:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499091#M132753</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-26T14:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499121#M132756</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235217"&gt;@Anirudh9&lt;/a&gt;&amp;nbsp;there are several working solutions posted. None work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235217"&gt;@Anirudh9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wrote the same code on Python. Maybe you could help me translate the same to SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The match rate is what my target value is. actual_rate is table 1, matrix_rate is table 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the value In actual_rate is higher than max of matrix_rate, I want the highest value of matrix_rate to be used. I think this code will help understand my problem a lot better.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;match_rate = []&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;actual_rate = [31,53,25,61,44,165,311,233]&amp;nbsp;&amp;nbsp;#These are samples, actual data is bigger, 30-40 rows&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;matrix_rate = [31,62,93,124,155,186,211,252,288]&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;for i in range(np.size(actual_rate)):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;if actual_rate[i] &amp;gt; max(matrix_rate):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;match_rate[i] = max(matrix_rate)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;else:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;temp1 = []&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;for j in range(np.size(matrix_rate)):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;p = matrix_rate[j] - actual_rate[i]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (p &amp;gt;= 0):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;temp1.append(p)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;match_rate[i] = min(temp1) + actual_rate[I]&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 14:43:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499121#M132756</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-26T14:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499211#M132792</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hey guys! I used your ideas and came up with this simple answer. Thank you so much for all the suggestions. This community is the best!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; x, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; max(y) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t2) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; x &amp;gt; (&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; max(y) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t2)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;union&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; x,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; min(y) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y&amp;gt;=x) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; t1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 18:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499211#M132792</guid>
      <dc:creator>Anirudh9</dc:creator>
      <dc:date>2018-09-26T18:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499311#M132845</link>
      <description>&lt;P&gt;This is a totally different question as the data is now horizontal.&lt;/P&gt;
&lt;P&gt;I don't know python by this is probably pretty close.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data _null_;

  array MATCH_RATE  [8] ;
  array ACTUAL_RATE [8] (31 53 25  61  44 165 311 233    ) ;  
  array MATRIX_RATE [9] (31 62 93 124 155 186 211 252 288) ;

  do I= 1 to dim(ACTUAL_RATE);
   
    if ACTUAL_RATE[I] &amp;gt; max(of MATRIX_RATE[*]) then 
      MATCH_RATE[I] = max(of MATRIX_RATE[*]); 
     
    else do;
      TEMP1=.;
      do J= 1 to dim(MATRIX_RATE);
         P = MATRIX_RATE[J] - ACTUAL_RATE[I];
         if P &amp;gt;= 0 then  TEMP1=min(TEMP1,P);
      end;
  
      MATCH_RATE[I] = TEMP1 + ACTUAL_RATE[I]; 
      putlog I=   MATCH_RATE[I]=;
   end;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I=1 MATCH_RATE1=31&lt;BR /&gt;I=2 MATCH_RATE2=62&lt;BR /&gt;I=3 MATCH_RATE3=31&lt;BR /&gt;I=4 MATCH_RATE4=62&lt;BR /&gt;I=5 MATCH_RATE5=62&lt;BR /&gt;I=6 MATCH_RATE6=186&lt;BR /&gt;I=8 MATCH_RATE8=252&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 22:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/499311#M132845</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-09-26T22:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Finding Closest Value to a List of Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/533037#M146104</link>
      <description>&lt;P&gt;Hi, if I wanna find the nearest lower one, I just change max to min lie following&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;create&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;test&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;x,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;min(y)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t2)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;y&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;x &amp;gt; (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;min(y)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t2)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;union&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;x,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;max(y)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t2&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;y&amp;lt;=x)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;y&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;t1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 19:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-Closest-Value-to-a-List-of-Values/m-p/533037#M146104</guid>
      <dc:creator>tampham92</dc:creator>
      <dc:date>2019-02-05T19:22:21Z</dc:date>
    </item>
  </channel>
</rss>

