<?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: How to use array to create a lookup table? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552909#M9257</link>
    <description>I am sorry that Code didn't work as it pointed out an error " Array subscript out of range at line 164 column 47" When I referring to the row 164, it had nothing special on the data.</description>
    <pubDate>Mon, 22 Apr 2019 15:29:09 GMT</pubDate>
    <dc:creator>learnin</dc:creator>
    <dc:date>2019-04-22T15:29:09Z</dc:date>
    <item>
      <title>How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552775#M9227</link>
      <description>&lt;P&gt;The question is about calculating the minimum fee. I have a dataset called busfares, which contains different station code, the destation code, type of fares. So much thanks to all of you if you wish to spend some time on my question.&lt;BR /&gt;&lt;BR /&gt;The dataset looks like this.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;srt_na srt srt_id dest_na dest dest_id adult_pri student_pri child_pri eldery_pri
abcde  abc  1     abcde    abc   1        0       0           0         0
abcde  abc  1     bbcde    bbc   2        5       4           4         1
abcde  abc  1     cbcde    cbc   3        7       5           5         1
abcde  abc  1     dbcde    dbc   4        7       5           5         1
abcde  abc  1     ebcde    ebc   5        10      6           6         1
                                  .
                                  .
                                  .
abcde  abc  1     ooooo    ooo   91       30.5    20          20        1
bbcde  bbc  2     abcde    abc    1       5       4           4         1
bbcde  bbc  2     bbcde    bbc    2       0       0           0         0
                                  .
                                  .
                                  .
ooooo  ooo  91    abcde    abc    1       30.5    20          20        1
ooooo  ooo  91    bbcde    bbc    2       30.5    20          20        1
                                  .
                                  .
                                  .
ooooo  ooo  91    ooooo    ooo    91      0       0           0         &lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;The question is how can I use four array to bulid the look up tables for different type of fares? The table should be look like that. And the row and column are representing different station name like row1 is representing abc, column1 is also representing abc as well&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;adult   1   2   3   4   ...
1       0   5   7   7   ...
2       5   0   10  10  ...
3       7   10  0   5   ...
4       7   10  5   0   ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 09:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552775#M9227</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T09:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552785#M9230</link>
      <description>How can you compute the minimum fee, when your data contains no fee information?&lt;BR /&gt;&lt;BR /&gt;Give an example of how to do that if you had no computer, working only with the printed data.</description>
      <pubDate>Mon, 22 Apr 2019 11:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552785#M9230</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T11:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552786#M9231</link>
      <description>No, there is different fare in the dataset. For example, adult_pric is actually the price for an adult traveling from one station to another station. Like 5(adult_fare) means that person travel from station "abcde" to station "bbcde".</description>
      <pubDate>Mon, 22 Apr 2019 11:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552786#M9231</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T11:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552792#M9233</link>
      <description>OK.  For that you can create a hash table directly from the original data.  I leave the task to others with better hashing skills than mine</description>
      <pubDate>Mon, 22 Apr 2019 11:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552792#M9233</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T11:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552795#M9234</link>
      <description>I am sorry, I have to use the array technique to finish this task. Since this is the requirement.</description>
      <pubDate>Mon, 22 Apr 2019 11:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552795#M9234</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T11:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552812#M9240</link>
      <description>Then you can choose between a three dimensional array, or 4 two dimensional arrays.&lt;BR /&gt;&lt;BR /&gt;For a single array:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;&lt;BR /&gt;Array plist [4, 91, 91] ;&lt;BR /&gt;set have;&lt;BR /&gt;plist [1, srt_id, dest_id] = adult_pri;&lt;BR /&gt;plist [2, srt_id, dest_id] = student_pri;&lt;BR /&gt;etc.</description>
      <pubDate>Mon, 22 Apr 2019 12:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552812#M9240</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T12:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552865#M9243</link>
      <description>&lt;P&gt;Now that I have my hands on a real keyboard instead of a handheld, here's a way to set up 4 two-dimensional arrays:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if _n_=1 then do;
      array adult {91, 91} _temporary_;
      array student {91, 91} _temporary_;
      array child {91, 91} _temporary_;
      array elderly {91, 91} _temporary_;
      do until (done);
         set have end=done;
         adult{srt_id, dest_id} = min(adult_pri, adult{srt_id, dest_id} ) ;
         student{srt_id, dest_id} = min(student_pri, student{srt_id, dest_id} ) ;
         child{srt_id, dest_id} = min(child_pri, child{srt_id, dest_id} ) ;
         elderly{srt_id, dest_id} = min(elderly_pri, elderly{srt_id, dest_id} ) ;
      end;
   end;
 
   * more DATA step code here to utilize the arrays;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The original question mentions something about finding the minimum price, which is the reason for applying the MIN function.&amp;nbsp; It's possible that I'm overcomplicating the problem in that regard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not use the array names (student, adult, child, elderly) as variable names in the same DATA step.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 14:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552865#M9243</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T14:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552888#M9249</link>
      <description>So much thanks for your reply. But I want to ask what is the meaning in the code "set have"</description>
      <pubDate>Mon, 22 Apr 2019 15:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552888#M9249</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T15:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552896#M9252</link>
      <description>Beside I would like to know the logic on how you input the fare from 1 srt_id to 91 dest_id. Should we use the nested do loop instead? Sorry for that, I am a new learner on SAS</description>
      <pubDate>Mon, 22 Apr 2019 15:11:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552896#M9252</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T15:11:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552902#M9255</link>
      <description>&lt;P&gt;There is a DO loop that says:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do until (done);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That loop accomplishes both of the things you are asking about.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The SET statement (set have; ) refers to the data set that you have that contains all the destinations and prices.&amp;nbsp; Each time through the loop executes the SET statement to read the next observation from your source of prices.&lt;/LI&gt;
&lt;LI&gt;Within the loop, after the SET statement executes, there are four assignment statements that each populate one element of an array.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 22 Apr 2019 15:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552902#M9255</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T15:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552909#M9257</link>
      <description>I am sorry that Code didn't work as it pointed out an error " Array subscript out of range at line 164 column 47" When I referring to the row 164, it had nothing special on the data.</description>
      <pubDate>Mon, 22 Apr 2019 15:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552909#M9257</guid>
      <dc:creator>learnin</dc:creator>
      <dc:date>2019-04-22T15:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use array to create a lookup table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552919#M9261</link>
      <description>I set the dimensions of the arrays at 91,91 because those were the largest values that appear in your sample data.  If you actually have larger values, you have to increase the array dimensions accordingly.&lt;BR /&gt;&lt;BR /&gt;There is no substitute for knowing what is in your data.&lt;BR /&gt;&lt;BR /&gt;If you are doing homework on arrays, there is no substitute for learning how arrays work.  You took a good first step by finding and posting the error message.  Next step: understand what the error message means.</description>
      <pubDate>Mon, 22 Apr 2019 15:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-use-array-to-create-a-lookup-table/m-p/552919#M9261</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-22T15:50:42Z</dc:date>
    </item>
  </channel>
</rss>

