<?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: Look-up from table with top and row and left column as indices in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489909#M128032</link>
    <description>&lt;P&gt;OK. Here is an example.&lt;/P&gt;
&lt;P&gt;The best way is using IML, if you have SAS/IML .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option validvarname=any;
data have;
input FILL      '73864'n    '37463'n    '37465'n    '72958'n     '20276'n;
cards;
   95826              6            1            5            8             2
    98574              2            9            1            9             1
    23847              1            3            8            4             7            
    95867              3            2            5            8             1
;
run;

proc sort data=have out=temp;
by fill;
run;
proc transpose data=temp out=lookup(where=(_NAME_ ne 'FILL'));
by fill;
var _all_;
run;
data lookup;
 set lookup;
 name=input(_name_,best32.);
run;
data want;
 if _n_=1 then do;
  if 0 then set lookup;
  declare hash h(dataset:'lookup');
  h.definekey('fill','name');
  h.definedata('col1');
  h.definedone();
 end;

Entry_zip=95867;    Destination_zip=20276; 
if h.find(key:Entry_zip,key:Destination_zip)=0 then zone=col1;
output;


Entry_zip=23847  ;    Destination_zip=37465  ; 
if h.find(key:Entry_zip,key:Destination_zip)=0 then zone=col1;
output;


run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 26 Aug 2018 12:56:01 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-08-26T12:56:01Z</dc:date>
    <item>
      <title>Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489894#M128019</link>
      <description>&lt;P&gt;I know how to do this fairly easy in Python pandas using lookup() but want to see how to do it in SAS. The problem is straight forward. I have this master list show the zone associated with any zip-code pair. For instance, if the origin zip code is 95826 and the destination zip code is 73864, then the corresponding zone is 6. This master list has 3000 rows and columns. I would appreciate keeping the code macro free. I just need the fundamental base SAS code or ideas and I can take it from there. Many people have suggested transposing then doing a join/merge. I don't think that will work here. Currently my office uses Excel VBA to do this then feeds the results back into SAS. Considering what we pay for SAS, I'm certain there's a way to do this in SAS. In python, the solution involves re-indexing the "Master List" data set so the zip codes along the vertical are the new row indices instead of the default 1,2,3,4,....&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For our discussion, let's say I got the data into SAS and it looks like the following&lt;/P&gt;&lt;P&gt;Master List of &lt;U&gt;&lt;STRONG&gt;zones&lt;/STRONG&gt;&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FILL&amp;nbsp; &amp;nbsp; &amp;nbsp; 73864&amp;nbsp; &amp;nbsp; 37463&amp;nbsp; &amp;nbsp; 37465&amp;nbsp; &amp;nbsp; 72958&amp;nbsp; &amp;nbsp; &amp;nbsp;20276&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 95826&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 98574&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; 23847&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; 95867&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; 39487&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; 39483&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Package_Weight&amp;nbsp; &amp;nbsp; Package_Height&amp;nbsp; &amp;nbsp; Package_Length&amp;nbsp; &amp;nbsp; Entry_zip&amp;nbsp; &amp;nbsp; Destination_zip&amp;nbsp; &amp;nbsp; &lt;U&gt;&lt;STRONG&gt;zone&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;32&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 95867&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20276&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23847&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;37465&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489894#M128019</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T12:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489896#M128021</link>
      <description>&lt;P&gt;In SAS, you would transform the data set into from-to pairs.&amp;nbsp; For example, the first few observations might look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;From&amp;nbsp; &amp;nbsp;To&amp;nbsp; &amp;nbsp; &amp;nbsp;Value&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;95826&amp;nbsp; 73864&amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;95826&amp;nbsp; 37463&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;95826&amp;nbsp; 37465&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That data set would be useful within a DATA step as a hash table, where the FROM TO combination is the index to the hash table, used to retrieve the VALUE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to retrieve the values in a procedure rather than a DATA step, there are other possibilities.&amp;nbsp; But those possibilities still begin with transforming the data.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489896#M128021</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-26T12:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489897#M128022</link>
      <description>Astounding, how do I get it in the form you suggest? Transpose will not do that.</description>
      <pubDate>Sun, 26 Aug 2018 12:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489897#M128022</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T12:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489900#M128025</link>
      <description>&lt;P&gt;What kind of style did your data store? A sas table or a Excel ? 12345 is not a valid sas name.&lt;/P&gt;
&lt;P&gt;Here are some ways:&lt;/P&gt;
&lt;P&gt;1) best way is using SAS/IML code.&lt;/P&gt;
&lt;P&gt;2) Hash Table&lt;/P&gt;
&lt;P&gt;3)Proc format&lt;/P&gt;
&lt;P&gt;4) Array Skill .&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489900#M128025</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-26T12:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489901#M128026</link>
      <description>&lt;P&gt;The master zip code list is an Excel doc. 12345 is not the sas file name; I'm saying the row observations are named sequentially as is normally the case 1 thru (# of observations).&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489901#M128026</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T12:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489904#M128027</link>
      <description>&lt;P&gt;Can you get the data into a SAS data set in any form at all?&amp;nbsp; Clearly what you posted is prior to that step.&amp;nbsp; So get the data into SAS, and describe the structure of what it looks like.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489904#M128027</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-26T12:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489906#M128029</link>
      <description>&lt;P&gt;Then you need offer this excel file.&lt;/P&gt;
&lt;P&gt;You need import this excel file into sas before doing look-up operator .&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489906#M128029</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-26T12:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489907#M128030</link>
      <description>I've updated the question to what the data set would look like in SAS.</description>
      <pubDate>Sun, 26 Aug 2018 12:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489907#M128030</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T12:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489908#M128031</link>
      <description>I've posted what the data will look like in SAS</description>
      <pubDate>Sun, 26 Aug 2018 12:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489908#M128031</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T12:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489909#M128032</link>
      <description>&lt;P&gt;OK. Here is an example.&lt;/P&gt;
&lt;P&gt;The best way is using IML, if you have SAS/IML .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option validvarname=any;
data have;
input FILL      '73864'n    '37463'n    '37465'n    '72958'n     '20276'n;
cards;
   95826              6            1            5            8             2
    98574              2            9            1            9             1
    23847              1            3            8            4             7            
    95867              3            2            5            8             1
;
run;

proc sort data=have out=temp;
by fill;
run;
proc transpose data=temp out=lookup(where=(_NAME_ ne 'FILL'));
by fill;
var _all_;
run;
data lookup;
 set lookup;
 name=input(_name_,best32.);
run;
data want;
 if _n_=1 then do;
  if 0 then set lookup;
  declare hash h(dataset:'lookup');
  h.definekey('fill','name');
  h.definedata('col1');
  h.definedone();
 end;

Entry_zip=95867;    Destination_zip=20276; 
if h.find(key:Entry_zip,key:Destination_zip)=0 then zone=col1;
output;


Entry_zip=23847  ;    Destination_zip=37465  ; 
if h.find(key:Entry_zip,key:Destination_zip)=0 then zone=col1;
output;


run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Aug 2018 12:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489909#M128032</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-26T12:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489910#M128033</link>
      <description>Thanks for this Ksharp. I need to read-up on this hash stuff and digest this code.</description>
      <pubDate>Sun, 26 Aug 2018 13:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489910#M128033</guid>
      <dc:creator>Badjuju</dc:creator>
      <dc:date>2018-08-26T13:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Look-up from table with top and row and left column as indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489912#M128034</link>
      <description>&lt;P&gt;Note that postal codes are NOT numbers. For example the code&amp;nbsp;04032 for Freeport Maine has a leading zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to start depends on what format your original list is in.&amp;nbsp; If it is a CSV or other type of text file then just read it in originally as from/to pairs.&amp;nbsp; For example if the file looks like this:&lt;/P&gt;
&lt;PRE&gt;FILL 73864 37463 37465 72958 20276
95826 6 1 5 8 2
98574 2 9 1 9 1
23847 1 3 8 4 7
95867 3 2 5 8 1&lt;/PRE&gt;
&lt;P&gt;you could read the first line and remember the codes for the columns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data zones ;
  infile zone truncover ;
  array cols (3000) $7 _temporary_;
  length from to $7 zone 8;
  if _n_=1 then do;
    input to @;
    do col=1 by 1 until(to=' ') ;
      input to @ ;
      cols(col)=to;
    end;
    ncols=col-1;
    retain ncols;
    input ;
  end;
  input from @;
  do col=1 to ncols ;
    to=cols(col);
    input zone @;
    output;
  end;
  keep from to zone;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can either use the data in a hash and join or merge or create a format or informat.&lt;/P&gt;
&lt;P&gt;You could easily transform the FROM/TO/ZONE variables into START/LABEL values to use with PROC FORMAT's CNTLIN= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data infmt;
  set zones ;
  retain fmtname 'ZONE' type 'I' ;
  length start $14 ;
  start = cat(from,to);
  rename zone=label;
run;
proc format cntlin=infmt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if we create your example data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Package_Weight Package_Height Package_Length Entry_zip :$7.  Destination_zip :$7. zone_expect ;
cards;
 2 10 32 95867 20276 1
 6 3 12 23847 37465 8
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is easy enough to use the INFORMAT to convert the from/to pair into a zone.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 set have ;
 zone = input(cat(entry_zip,destination_zip),zone.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       Package_    Package_    Package_    Entry_    Destination_     zone_
Obs     Weight      Height      Length      zip          zip         expect    zone

 1         2          10          32       95867        20276           1        1
 2         6           3          12       23847        37465           8        8&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Aug 2018 14:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Look-up-from-table-with-top-and-row-and-left-column-as-indices/m-p/489912#M128034</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-26T14:35:11Z</dc:date>
    </item>
  </channel>
</rss>

