<?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: Looking up values in another table. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75779#M21991</link>
    <description>data newdata;&lt;BR /&gt;
  set table1;&lt;BR /&gt;
    set table2 key = depcode;&lt;BR /&gt;
     if (not _iorc_ = %sysrc(_sok)) then do;&lt;BR /&gt;
         Department = ' ' ;    &lt;BR /&gt;
         errtxt = " ";&lt;BR /&gt;
         _error_ = 0;&lt;BR /&gt;
      end;&lt;BR /&gt;
run;

Sorry, no parentheses needed there (Code off the top of my head may sometimes contain syntax errors).&lt;BR /&gt;
&lt;BR /&gt;
This should give you the starting point to solve your problem.&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Flip</description>
    <pubDate>Fri, 27 Feb 2009 13:02:42 GMT</pubDate>
    <dc:creator>Flip</dc:creator>
    <dc:date>2009-02-27T13:02:42Z</dc:date>
    <item>
      <title>Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75778#M21990</link>
      <description>In Table1 there are many individuals. The individuals can can have values 1 - 10 for the variable DepCode.&lt;BR /&gt;
&lt;BR /&gt;
In Table2 there are only the variables DepCode and Department. The variable Department contains the 10 DepCode values translated to text.&lt;BR /&gt;
&lt;BR /&gt;
I want to look up the DepCode in Table2 and have the Department text transferred to a new variable, why not Department, in Table1.&lt;BR /&gt;
&lt;BR /&gt;
I thought I could use LOCATEC or WHERE, but I get the error message: &lt;I&gt;"The function X????? is unknown, or cannot be accessed."&lt;/I&gt;.&lt;BR /&gt;
&lt;BR /&gt;
How could I solve this simple programming problem?&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Fri, 27 Feb 2009 11:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75778#M21990</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-27T11:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75779#M21991</link>
      <description>data newdata;&lt;BR /&gt;
  set table1;&lt;BR /&gt;
    set table2 key = depcode;&lt;BR /&gt;
     if (not _iorc_ = %sysrc(_sok)) then do;&lt;BR /&gt;
         Department = ' ' ;    &lt;BR /&gt;
         errtxt = " ";&lt;BR /&gt;
         _error_ = 0;&lt;BR /&gt;
      end;&lt;BR /&gt;
run;

Sorry, no parentheses needed there (Code off the top of my head may sometimes contain syntax errors).&lt;BR /&gt;
&lt;BR /&gt;
This should give you the starting point to solve your problem.&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Flip</description>
      <pubDate>Fri, 27 Feb 2009 13:02:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75779#M21991</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-02-27T13:02:42Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75780#M21992</link>
      <description>Thanks!&lt;BR /&gt;
&lt;BR /&gt;
But&lt;BR /&gt;
&lt;BR /&gt;
set table2 (key = depcode);&lt;BR /&gt;
&lt;BR /&gt;
gives &lt;B&gt;ERROR 22-7: Invalid option name KEY.&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Fri, 27 Feb 2009 13:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75780#M21992</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-02-27T13:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75781#M21993</link>
      <description>The SET statement SAS Data step DOC provides the answer to your error.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 27 Feb 2009 13:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75781#M21993</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-02-27T13:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75782#M21994</link>
      <description>If I write the code like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;data newdata;&lt;BR /&gt;
set table1;&lt;BR /&gt;
set table2 key = depcode;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
I get the error message: No key variables have been defined for file table2&lt;BR /&gt;
&lt;BR /&gt;
If I write like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;data newdata;&lt;BR /&gt;
set table1;&lt;BR /&gt;
set table2;  key = depcode;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
the code runs, but I get the Departments from table2 from the beginning, with no regard to if the DepCode in table2 corresponds to the DepCode in table1.</description>
      <pubDate>Mon, 02 Mar 2009 12:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75782#M21994</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-02T12:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75783#M21995</link>
      <description>As Scott pointed out, read the documentation, don't expect cut and paste code from a forum.  Lookups using a Key are quite powerful.  &lt;BR /&gt;
&lt;BR /&gt;
The quick answer to your question is that you should index your lookup dataset on the key you are using.&lt;BR /&gt;
&lt;BR /&gt;
Flip</description>
      <pubDate>Mon, 02 Mar 2009 12:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75783#M21995</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-02T12:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75784#M21996</link>
      <description>Just a version using PROC SQL.&lt;BR /&gt;
&lt;BR /&gt;
You could also use the data set "department" to create a format (example in SAS OnlineDoc for Proc Format) and then apply this format in the Individuals table on the field "DepCode".&lt;BR /&gt;
If you need the department names for printing only this would avoid to create redundant data in a second table (using a format statement). If you still would want to create a new variable: DepartmentName=put(depcode,depfmt.);&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data department;&lt;BR /&gt;
  depcode=1; department='a';output;&lt;BR /&gt;
  depcode=2; department='b';output;&lt;BR /&gt;
  depcode=3; department='c';output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data individuals;&lt;BR /&gt;
  IndCode=1;DepCode=1;output;&lt;BR /&gt;
  IndCode=2;DepCode=3;output;&lt;BR /&gt;
  IndCode=3;DepCode=2;output;&lt;BR /&gt;
  IndCode=4;DepCode=5;output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  create table individuals2 as&lt;BR /&gt;
    select ind.*,dep.department&lt;BR /&gt;
      from individuals ind left join department dep&lt;BR /&gt;
        on ind.depcode=dep.depcode;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc datasets lib=work nodetails nolist;&lt;BR /&gt;
  delete individuals;&lt;BR /&gt;
  change individuals2=individuals;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=individuals;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 02 Mar 2009 12:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75784#M21996</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-03-02T12:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75785#M21997</link>
      <description>"Read the documentation", could be the answer to all questions probably, in one way or the other.&lt;BR /&gt;
&lt;BR /&gt;
But I have been searching the documentation för several hours without any result.&lt;BR /&gt;
&lt;BR /&gt;
I didn't cut and paste your code. I wrote it by myself.&lt;BR /&gt;
&lt;BR /&gt;
"Lookups using a Key are quite powerful." I can imagine that if I knew how to use it.&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Mon, 02 Mar 2009 13:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75785#M21997</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-02T13:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75786#M21998</link>
      <description>GOOGLE "sas set key"&lt;BR /&gt;
&lt;BR /&gt;
www2.sas.com/proceedings/sugi25/25/po/25p234.pdf&lt;BR /&gt;
ftp.sas.com/samples/A60409&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.jmu.edu/docs/sasdoc/sashtml/accdb/z0612367.htm" target="_blank"&gt;www.jmu.edu/docs/sasdoc/sashtml/accdb/z0612367.htm&lt;/A&gt;</description>
      <pubDate>Mon, 02 Mar 2009 13:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75786#M21998</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-02T13:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75787#M21999</link>
      <description>Suggest you reply to the group with SASLOG output revealing your SAS DATA and PROC step execution adjacent to the failing DATA step, also showing the error message you receive.  The critical contributing factor here is the location of your KEY= parameter on the SET statement - something the DOC can help convey.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 02 Mar 2009 16:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75787#M21999</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-02T16:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75788#M22000</link>
      <description>An executable example.&lt;BR /&gt;
NOTE: you need to have an index on the lookup set, and you need to handle errors where there is no match.  For small cases the format that Patrick refered to is great, but when you get into very large lookups this method is better.  &lt;BR /&gt;
&lt;BR /&gt;
data table2(index = (depcode));&lt;BR /&gt;
depcode=1; department='a';output;&lt;BR /&gt;
depcode=2; department='b';output;&lt;BR /&gt;
depcode=3; department='c';output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data table1;&lt;BR /&gt;
IndCode=1;DepCode=1;output;&lt;BR /&gt;
IndCode=2;DepCode=3;output;&lt;BR /&gt;
IndCode=3;DepCode=2;output;&lt;BR /&gt;
IndCode=4;DepCode=5;output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 data newdata;&lt;BR /&gt;
 set table1;&lt;BR /&gt;
 set table2 key = depcode;&lt;BR /&gt;
 if (not _iorc_ = %sysrc(_sok)) then do;&lt;BR /&gt;
 Department = ' ' ;&lt;BR /&gt;
 _error_ = 0;&lt;BR /&gt;
 end;&lt;BR /&gt;
 run;</description>
      <pubDate>Mon, 02 Mar 2009 17:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75788#M22000</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-02T17:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looking up values in another table.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75789#M22001</link>
      <description>Thankyou all, for your commitment.&lt;BR /&gt;
&lt;BR /&gt;
It worked to follow the above executable example.&lt;BR /&gt;
&lt;BR /&gt;
Susan</description>
      <pubDate>Tue, 03 Mar 2009 10:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Looking-up-values-in-another-table/m-p/75789#M22001</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-03T10:06:15Z</dc:date>
    </item>
  </channel>
</rss>

