<?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 do I lookup values from a table with defintions in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546946#M16828</link>
    <description>&lt;P&gt;I would probably transpose the data and apply the lookup logic from there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input type shape count;
datalines;
1	1	57
4	1	127
9	2	35
9	2	87
;

data two;
input format $	id	name $;
datalines;
type	1	blue
type	4	gray
type	9	red
shape	1	round
shape	2	circle
;

proc sort data=two;
   by id;
run;

proc transpose data=two out=lookup(drop=_NAME_);
   by id;
   id format;
   var name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Mar 2019 16:38:02 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-03-28T16:38:02Z</dc:date>
    <item>
      <title>How do I lookup values from a table with defintions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546930#M16825</link>
      <description>&lt;P&gt;Is there a procedure or other easy way to perform the lookup below? Or do I have to transpose the definition table and do a join on each column? My dataset contains many variables where I need to perform the this operation, so if there is a convenient way of doing this dynamically that would help allot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dataset:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;shape&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&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;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;TD&gt;shape&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;blue&lt;/TD&gt;&lt;TD&gt;round&lt;/TD&gt;&lt;TD&gt;57&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;gray&lt;/TD&gt;&lt;TD&gt;round&lt;/TD&gt;&lt;TD&gt;127&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;red&lt;/TD&gt;&lt;TD&gt;circle&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;red&lt;/TD&gt;&lt;TD&gt;circle&lt;/TD&gt;&lt;TD&gt;87&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 28 Mar 2019 15:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546930#M16825</guid>
      <dc:creator>JoeSt</dc:creator>
      <dc:date>2019-03-28T15:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: How do I lookup values from a table with defintions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546941#M16827</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as
   select b.name as type,b.format as shape, a.count
   from dataset as a
        left join
        definition as b
        on a.type=b.id
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Proc SQL will reorder the data. If you require the data in a specific order then add a variable to the dataset with the order you want, include a statement after the ON clause of : order by a.ordervariablename.&lt;/P&gt;
&lt;P&gt;If you don't include a the order variable in the Select variable list then you'll likely get a note about that. The a. and b. are aliases that temporarily reference the data sets for short hand.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 16:21:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546941#M16827</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T16:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I lookup values from a table with defintions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546946#M16828</link>
      <description>&lt;P&gt;I would probably transpose the data and apply the lookup logic from there&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input type shape count;
datalines;
1	1	57
4	1	127
9	2	35
9	2	87
;

data two;
input format $	id	name $;
datalines;
type	1	blue
type	4	gray
type	9	red
shape	1	round
shape	2	circle
;

proc sort data=two;
   by id;
run;

proc transpose data=two out=lookup(drop=_NAME_);
   by id;
   id format;
   var name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2019 16:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546946#M16828</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-28T16:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I lookup values from a table with defintions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546956#M16829</link>
      <description>&lt;P&gt;Do you really need new character variables (like TYPE and SHAPE) in the final dataset? In many applications formatted numeric values would be sufficient. In this case you wouldn't even need a new dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create formats */

proc format cntlin=two(rename=(format=fmtname id=start name=label));
run;

/* Assign formats */

proc datasets lib=work nolist;
modify one;
format type  type.
       shape shape.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(using draycut's dataset names).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If some of the variable names were not suitable as format names (e.g. ending in a number), a bit more work would be required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The FORMAT statement in the PROC DATASETS step could be made more dynamic if needed.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 17:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-do-I-lookup-values-from-a-table-with-defintions/m-p/546956#M16829</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-03-28T17:05:54Z</dc:date>
    </item>
  </channel>
</rss>

