<?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: Dynamically rename a table's variable names with another table's variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821068#M324147</link>
    <description>Done.&lt;BR /&gt;Thanks!</description>
    <pubDate>Thu, 30 Jun 2022 07:28:01 GMT</pubDate>
    <dc:creator>Zeus_Olympus</dc:creator>
    <dc:date>2022-06-30T07:28:01Z</dc:date>
    <item>
      <title>Dynamically rename a table's variable names with another table's variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821065#M324145</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have table A with two variables RET_VAR and CODE having values as shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;U&gt;RET_VAR&lt;/U&gt;    &lt;U&gt;CODE&lt;/U&gt;
Blue	   345V
Green	   678V
Orange	   546V
White	   879V
Black	   234V
Yellow	   987V
Purple	   234V&lt;/PRE&gt;&lt;P&gt;and&amp;nbsp; a table B with many variables Var(i) with names:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;   Black	   Blue	          Brown	          Gray	          Green	         Maroon	         Olive	          Orange	   Pink	         Purple	         Silver   	White	         Yellow
 3.456,00 	 4.792,20 	 5.901,60 	 6.784,20 	 7.440,00 	 7.869,00 	 8.071,20 	 8.046,60 	 7.795,20 	 7.317,00 	 9.362,80 	 2.314,00 	 3.906,20 
 5.634,00 	 5.067,00 	 4.500,00 	 3.933,00 	 3.366,00 	 2.799,00 	 2.232,00 	 1.665,00 	 1.098,00 	 531,00 	 2.345,00 	 1.778,00 	 1.211,00 
 4.758,00 	 4.191,00 	 3.624,00 	 3.057,00 	 2.490,00 	 1.923,00 	 1.356,00 	 789,00 	 222,00 	 6.532,00 	 5.965,00 	 5.398,00 	 4.831,00 &lt;/PRE&gt;&lt;P&gt;I need to rename the variables in table B that are ONLY included in table A with the values of variable CODE in table A.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be welcomed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 07:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821065#M324145</guid>
      <dc:creator>Zeus_Olympus</dc:creator>
      <dc:date>2022-06-30T07:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically rename a table's variable names with another table's variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821067#M324146</link>
      <description>&lt;P&gt;Please post the expected output and data in usable form.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 07:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821067#M324146</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-06-30T07:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically rename a table's variable names with another table's variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821068#M324147</link>
      <description>Done.&lt;BR /&gt;Thanks!</description>
      <pubDate>Thu, 30 Jun 2022 07:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821068#M324147</guid>
      <dc:creator>Zeus_Olympus</dc:creator>
      <dc:date>2022-06-30T07:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically rename a table's variable names with another table's variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821158#M324191</link>
      <description>&lt;P&gt;Note that those are awkward SAS variable names so you'll need to refer to them as '345V'n in future usage.&amp;nbsp;&lt;BR /&gt;Perhaps a label may be a better approach?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will change the names.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table change_list as
select * from tableA
where upper(ret_var) in (select trim(upper(name)) from sashelp.vcolumn where libname='WORK' and memname='TABLEB');
quit;


data _null_;
set change_list end=eof;

if _n_ = 1 then 
call execute ('proc datasets lib=work nodetails nolist; modify TableB; rename ');

call execute (catt(ret_var, ' = ', nliteral(code)));
call execute (' ');
if eof then call execute(';run; quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To create labels instead, change the word rename to LABEL and remove the NLITERAL function. If you're trying to export the data or have it in a report, labels are easier to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set change_list end=eof;

if _n_ = 1 then 
call execute ('proc datasets lib=work nodetails nolist; modify TableB; label ');

call execute (catt(ret_var, ' = ', code));
call execute (' ');
if eof then call execute(';run; quit;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2022 15:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821158#M324191</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-30T15:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically rename a table's variable names with another table's variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821247#M324223</link>
      <description>&lt;P&gt;Black an Purple have the same value, so renaming won't work and as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; already said, using names like "234V" forces you to use the hardly readable '234V'n all the time =&amp;gt; you don't want this.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2022 05:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-rename-a-table-s-variable-names-with-another-table-s/m-p/821247#M324223</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-07-01T05:02:30Z</dc:date>
    </item>
  </channel>
</rss>

