<?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: new user trying to find the right lookup function in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75139#M21786</link>
    <description>Try this.  It creates a lookup table and adds the ATaxrate to the base table based on the index.&lt;BR /&gt;
&lt;BR /&gt;
data taxrates( index = (stidx = (year Adjacentstate)));&lt;BR /&gt;
Year=2008; AdjacentState='AK'; ATaxrate=0.25; output;&lt;BR /&gt;
Year=2009; AdjacentState='AK'; ATaxrate=0.35; output;&lt;BR /&gt;
Year=2009; AdjacentState='NY'; ATaxrate=0.30; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
State='AK'; Year=2009; Taxrate='0.35'; AdjacentState='NY'; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
set have;&lt;BR /&gt;
set taxrates  key = stidx / unique;&lt;BR /&gt;
if _iorc_&amp;gt;0 then ATaxrate = . ;&lt;BR /&gt;
run;</description>
    <pubDate>Wed, 14 Oct 2009 12:31:28 GMT</pubDate>
    <dc:creator>Flip</dc:creator>
    <dc:date>2009-10-14T12:31:28Z</dc:date>
    <item>
      <title>new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75133#M21780</link>
      <description>I am currently trying to write a SAS program to mimic a project I just did in Excel using the Vlookup function.  I have a table with the following variables (simplified):&lt;BR /&gt;
&lt;BR /&gt;
State  Year  Taxrate  AdjacentState   AdjacentTax&lt;BR /&gt;
&lt;BR /&gt;
I also made a variable which combines the state and year, in order to have an unique identifier for each row.&lt;BR /&gt;
&lt;BR /&gt;
I have values for the first four variables.  The fourth has to reference the tax rate from the adjacent state in the same year.  This is where I am stuck.  Is there a procedure in SAS which will do this, like VLookup in excel?  And if not, should I just try to use inelegant SQL table joins instead?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the assistance</description>
      <pubDate>Thu, 08 Oct 2009 18:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75133#M21780</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-08T18:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75134#M21781</link>
      <description>With a DATA step approach, you use a PUT function in an assignment statement.  The second argument in the PUT function references a SAS FORMAT.  You will need to use PROC FORMAT to build your look-up argument (START and possibly an END) data-string and a "LABEL" which SAS returns in the assignment statement, similar to VLOOKUP.  &lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 08 Oct 2009 18:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75134#M21781</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-10-08T18:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75135#M21782</link>
      <description>Extending Scott's post, to show you an example of syntax:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
formats:&lt;BR /&gt;&lt;BR /&gt;
  '2009AK' = '0.20'&lt;BR /&gt;&lt;BR /&gt;
  '2008AK' = '0.25'&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
data step:&lt;BR /&gt;&lt;BR /&gt;
  RATE=put(YEAR ||STATE, $rate.);&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;DIV style="background:#ddd"&gt;&lt;BR /&gt;&lt;BR /&gt;
&amp;nbsp;Note: If you have a numeric YEAR and want a numeric RATE, this becomes:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&amp;nbsp;RATE=&lt;B&gt;input(&lt;/B&gt; &amp;nbsp;  put( &amp;nbsp; &lt;I&gt;put(YEAR,4.)&lt;/I&gt; &amp;nbsp;  ||STATE, $rate.) &amp;nbsp;   &lt;B&gt;,32.)&lt;/B&gt;;&lt;BR /&gt;&lt;BR /&gt;
  &lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   ^ &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   ^  &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   ^  &lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  |  &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  |  &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  The bit in italics converts year to a string&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   |  &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   |  &lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   |  &lt;BR /&gt;
&lt;SPAN style="width: 40px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  This bit applies the format&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;   |  &lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  |  &lt;BR /&gt;&lt;BR /&gt;
&lt;SPAN style="width: 45px;"&gt;&amp;nbsp; &lt;/SPAN&gt;  The bit in bold converts the rate from a string to a number&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;/DIV&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
Another solution is to use hash tables, which can lookup values using several keys, without having to concatenate keys into a single key. Probably when you are a bit more familiar with sas though. Familiarise yourself with formats, and put hash tables on your radar.</description>
      <pubDate>Tue, 13 Oct 2009 03:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75135#M21782</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-10-13T03:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75136#M21783</link>
      <description>(Double-Post Deleted)</description>
      <pubDate>Tue, 13 Oct 2009 04:06:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75136#M21783</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-13T04:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75137#M21784</link>
      <description>Thank you for the further clarification.  I looked into proc format, but it seems that I have to specify all the formats in advance, and in this instance I'd have to list the tax rate for each state/year combination in the code.  This could work once, but I would want something that can process additional tables with new tax rates.  I would want the format to assign a tax rate to each state/year combination based on the table, then in the data step, apply the format to the AdjacentState variable so the AdjacentTaxRate is returned.  So for the format, it might be:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
value $rate&lt;BR /&gt;
stateyear = taxrate;&lt;BR /&gt;
&lt;BR /&gt;
rather than&lt;BR /&gt;
&lt;BR /&gt;
'2009AK' = '0.20'&lt;BR /&gt;
&lt;BR /&gt;
then for the data step, it would be the same, with AdjacentTaxRate=put(YEAR||STATE, $rate)&lt;BR /&gt;
&lt;BR /&gt;
Is that close to what I should be doing?&lt;BR /&gt;
&lt;BR /&gt;
I really appreciate the input.</description>
      <pubDate>Tue, 13 Oct 2009 04:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75137#M21784</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-13T04:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75138#M21785</link>
      <description>Have one more look at Proc Format and there at cntlin and cntlout&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
... or use simple SQL syntax:&lt;BR /&gt;
&lt;BR /&gt;
data taxrates;&lt;BR /&gt;
  Year=2008; State='AK'; Taxrate=0.25; output;&lt;BR /&gt;
  Year=2009; State='AK'; Taxrate=0.35; output;&lt;BR /&gt;
  Year=2009; State='NY'; Taxrate=0.30; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  State='AK'; Year=2009; Taxrate='0.35'; AdjacentState='NY'; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table want as&lt;BR /&gt;
    select h.state, h.year, h.taxrate, h.AdjacentState,t.taxrate format=4.2 as AdjacentTax&lt;BR /&gt;
      from have as h left join taxrates as t&lt;BR /&gt;
        on h.year=t.year and h.AdjacentState=t.state;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
... or use a hash object:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi29/238-29.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi29/238-29.pdf&lt;/A&gt;&lt;BR /&gt;
(article by one of my absolute favourites in the SAS field - advanced!)</description>
      <pubDate>Tue, 13 Oct 2009 07:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75138#M21785</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-10-13T07:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: new user trying to find the right lookup function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75139#M21786</link>
      <description>Try this.  It creates a lookup table and adds the ATaxrate to the base table based on the index.&lt;BR /&gt;
&lt;BR /&gt;
data taxrates( index = (stidx = (year Adjacentstate)));&lt;BR /&gt;
Year=2008; AdjacentState='AK'; ATaxrate=0.25; output;&lt;BR /&gt;
Year=2009; AdjacentState='AK'; ATaxrate=0.35; output;&lt;BR /&gt;
Year=2009; AdjacentState='NY'; ATaxrate=0.30; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
State='AK'; Year=2009; Taxrate='0.35'; AdjacentState='NY'; output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data have2;&lt;BR /&gt;
set have;&lt;BR /&gt;
set taxrates  key = stidx / unique;&lt;BR /&gt;
if _iorc_&amp;gt;0 then ATaxrate = . ;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 14 Oct 2009 12:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/new-user-trying-to-find-the-right-lookup-function/m-p/75139#M21786</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-10-14T12:31:28Z</dc:date>
    </item>
  </channel>
</rss>

