<?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: Vlookup Table in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258901#M7050</link>
    <description>&lt;P&gt;Here's one approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format cntlin=lookup (rename=(field=fmtname value=start name=label));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a format equivalent to having hard-coded along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value color 1='Red' 2='Orange' 3='Green';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use the format in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;name1 = put(val1, color.);&lt;/P&gt;
&lt;P&gt;name2 = put(val2, color.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Mar 2016 18:33:52 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-03-24T18:33:52Z</dc:date>
    <item>
      <title>Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258896#M7049</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Can you please help, my data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1&lt;/P&gt;&lt;P&gt;Field &amp;nbsp; val1 val2&lt;/P&gt;&lt;P&gt;Color&amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;Color &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Test &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table: Lookup table looks like this:&lt;/P&gt;&lt;P&gt;Field &amp;nbsp; &amp;nbsp;Value &amp;nbsp; &amp;nbsp;Name&lt;/P&gt;&lt;P&gt;Color &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Red&lt;/P&gt;&lt;P&gt;Color &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Orange&lt;/P&gt;&lt;P&gt;Color &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Green&lt;/P&gt;&lt;P&gt;Test &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yes&lt;/P&gt;&lt;P&gt;Test &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I want Table 1 to merge with the Lookup table and add the new field "Name 1 and Name 2" -- my final table should look like this:&lt;/P&gt;&lt;P&gt;Field &amp;nbsp; val1 val2 &amp;nbsp; Name1 &amp;nbsp; Name2&lt;/P&gt;&lt;P&gt;Color&amp;nbsp; &amp;nbsp;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;Orange &amp;nbsp; Green&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Color &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;Red &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Red&lt;/P&gt;&lt;P&gt;test &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yes &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yes&lt;/P&gt;&lt;P&gt;test &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp;yes &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 23:32:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258896#M7049</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2016-03-24T23:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258901#M7050</link>
      <description>&lt;P&gt;Here's one approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format cntlin=lookup (rename=(field=fmtname value=start name=label));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That gives you a format equivalent to having hard-coded along these lines:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;/P&gt;
&lt;P&gt;value color 1='Red' 2='Orange' 3='Green';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use the format in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;name1 = put(val1, color.);&lt;/P&gt;
&lt;P&gt;name2 = put(val2, color.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 18:33:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258901#M7050</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-24T18:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258999#M7052</link>
      <description>&lt;P&gt;Thank you this worked - but I have many variables and each needs a different formatting , i updated my data in my question, any insights on how I can call different formats for different values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2016 23:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/258999#M7052</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2016-03-24T23:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259005#M7054</link>
      <description>&lt;PRE&gt;



data Table1;
input Field  $ val1 val2;
cards;
Color   2      3
Color   1      1 
Test     1       1
Test      1      0
;
run;
 
data Lookup;
input Field $   Value    Name $;
cards;
Color     1            Red
Color     2            Orange
Color     3            Green
Test       1            yes
Test       0            no
;
run;
data want;
 if _n_ eq 1 then do;
  if 0 then set Lookup;
  declare hash h(dataset:'Lookup');
  h.definekey('Field','Value');
  h.definedata('Name');
  h.definedone();
 end;
set Table1;
call missing(Name);
rc=h.find(key:Field ,key:val1 ); Name1=Name;
call missing(Name);
rc=h.find(key:Field ,key:val2 ); Name2=Name;
drop rc value Name ;
run;


&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2016 13:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259005#M7054</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-29T13:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259006#M7055</link>
      <description>That worked -- Thank you Thank you</description>
      <pubDate>Fri, 25 Mar 2016 01:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259006#M7055</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2016-03-25T01:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259011#M7056</link>
      <description>&lt;P&gt;PUTC/PUTN allow the second parameter, the format to be dynamic or variable driven.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 02:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259011#M7056</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-25T02:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259235#M7067</link>
      <description>&lt;P&gt;Thank you , can you please show me an example how can I call in different formats for the field values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will appreciate your help.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2016 20:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259235#M7067</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2016-03-26T20:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259238#M7068</link>
      <description>&lt;P&gt;Use your lookup table to define formats. &amp;nbsp;You can use the CNTLIN= option on PROC FORMAT to do it from the data if you want.&lt;/P&gt;
&lt;P&gt;Then just use arrays to loop over your VAL variables and create the value of your NAME variables using PUTN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  array value val1-val2 ;
  array name $32 name1-name2 ;
  do over value ;
    name = putn(value,cats(field,'.'));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't like DO OVER then use DO I=1 to DIM(VALUE) and add all of the extra index notations to the array name references.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2016 22:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259238#M7068</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-26T22:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259239#M7069</link>
      <description>&lt;P&gt;Use your lookup table to define formats. &amp;nbsp;You can use the CNTLIN= option on PROC FORMAT to do it from the data if you want.&lt;/P&gt;
&lt;P&gt;Then just use arrays to loop over your VAL variables and create the value of your NAME variables using PUTN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  array value val1-val2 ;
  array name $32 name1-name2 ;
  do over value ;
    name = putn(value,cats(field,'.'));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't like DO OVER then use DO I=1 to DIM(VALUE) and add all of the extra index notations to the array name references.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2016 22:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/259239#M7069</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-26T22:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Vlookup Table</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/260585#M7111</link>
      <description>&lt;P&gt;PROC SQL solution, using&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;'s data sets above:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data Table1;
input Field  $ val1 val2;
cards;
Color   2      3
Color   1      1 
Test     1       1
Test      1      0
;
run;
 
data Lookup;
input Field $   Value    Name $;
cards;
Color     1            Red
Color     2            Orange
Color     3            Green
Test       1            yes
Test       0            no
;
run;

proc sql;
	create table want 
	as
	select T.Field
		, T.val1
		, T.val2
		, L1.Name as Name1
		, L2.Name as Name2
	from Table1 as T
	left join Lookup as L1
	 on L1.Value = T.Val1
	 and L1.Field = T.Field
	left join Lookup as L2
	 on L2.Value = T.Val2
	 and L2.Field = T.Field;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Mar 2016 23:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Vlookup-Table/m-p/260585#M7111</guid>
      <dc:creator>DSnyder</dc:creator>
      <dc:date>2016-03-31T23:35:15Z</dc:date>
    </item>
  </channel>
</rss>

