<?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: lookup within an array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268828#M53253</link>
    <description>&lt;P&gt;example data and calculation in excel attached.&lt;/P&gt;</description>
    <pubDate>Fri, 06 May 2016 15:40:12 GMT</pubDate>
    <dc:creator>iamthejvd</dc:creator>
    <dc:date>2016-05-06T15:40:12Z</dc:date>
    <item>
      <title>lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268801#M53243</link>
      <description>&lt;P&gt;Doing an array and I want the formula in the array to be a lookup, something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data table.population;&lt;BR /&gt;set table.population;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Array income_(n) &amp;nbsp;income_1 - income _100;&lt;/P&gt;&lt;P&gt;Array age_(n) age_1-age_100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do n=1 to 100;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; if n=1 then age_(n) = current_age;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; else age_(n) = age_(n-1)+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do n=1 to 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color="#FF0000"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; income_(n) = lookup(age_(n), table.age_by_income, Income);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the lookup would be somthing like a vlookup in excel, returning the income based on the age array.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 14:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268801#M53243</guid>
      <dc:creator>iamthejvd</dc:creator>
      <dc:date>2016-05-06T14:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268810#M53246</link>
      <description>&lt;P&gt;Please provide a sample data and desired output.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 14:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268810#M53246</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-05-06T14:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268813#M53247</link>
      <description>&lt;P&gt;I think you are looking for the WHICHN (or WHICHC if using character variables).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whichn returns the position in an array that matches a specified value.&lt;/P&gt;
&lt;P&gt;For instance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x = whichn(23, of age_(*)); Would return the which element of the array Age_ has the value of 23 or a 0 if not found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if I wanted to find an associated value I might use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;y = Income (whichn(23,of age_(*))); to find the value in the income array that is in the same position as 23 in the age array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea what you meand by table.age_by_Income. If you are intending to use a different dataset then that will not work at all in the manner you think. It may be possible in Proc Sql.&lt;/P&gt;
&lt;P&gt;You may need to provide a more concrete example, with values for variables of your input and expected output. If you want code tested provide the data in the form of a datastep that reads a datalines or cards data section.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 14:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268813#M53247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-06T14:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268816#M53249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84460"&gt;@iamthejvd﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Most probably, you can define a numeric informat, say INC_AGE, from the table "age_by_income" and then define income_(n) like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;income_(n) = input(put(age_(n), 3.), inc_age.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If&amp;nbsp;&lt;SPAN&gt;table "age_by_income" contains age groups (such as "20-24", "25-30" etc.), format 3. in the above code will be replaced by a user-defined format. For more specific advice we would need to know what "age_by_income" looks like.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 15:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268816#M53249</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-06T15:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268828#M53253</link>
      <description>&lt;P&gt;example data and calculation in excel attached.&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 15:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268828#M53253</guid>
      <dc:creator>iamthejvd</dc:creator>
      <dc:date>2016-05-06T15:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: lookup within an array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268841#M53260</link>
      <description>&lt;P&gt;Thanks for providing the data. You can create the informat I mentioned with the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data inc_age;
infile cards eof=last;
retain fmtname '@inc_age';
input start label;
output;
return;
last: 
  hlo='O';
  label=.;
  output;
cards; 
30 7.50
31 13.53
32 8.66
33 11.13
34 14.46
35 15.73
36 13.01
37 16.24
38 6.78
39 12.30
40 16.26
41 14.46
42 15.73
43 13.01
;

proc format cntlin=inc_age;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use the assignment statement from my previous post without any change:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;income_&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;age_&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; inc_age&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please make sure to fix your ARRAY statements by deleting the "(n)".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2016 16:12:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/lookup-within-an-array/m-p/268841#M53260</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-06T16:12:33Z</dc:date>
    </item>
  </channel>
</rss>

