<?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: Rename variables in all tables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540123#M16637</link>
    <description>Thank you so much. It worked</description>
    <pubDate>Mon, 04 Mar 2019 17:43:30 GMT</pubDate>
    <dc:creator>AZIQ1</dc:creator>
    <dc:date>2019-03-04T17:43:30Z</dc:date>
    <item>
      <title>Rename variables in all tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540099#M16632</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to rename a variable in my data tables. I have 50 data sets. The field in all tables has the same starting name "Table_" etc. example:&lt;/P&gt;&lt;P&gt;Table_1 in data set 1&lt;/P&gt;&lt;P&gt;Table_2 in data set 2&lt;/P&gt;&lt;P&gt;Table_3 in data set 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use a single rename statement in a macro to rename all "Table_:" to "ID_Number"&lt;/P&gt;&lt;P&gt;I tried using wild card ":" but it did not change it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this code:&lt;/P&gt;&lt;P&gt;rename Table: = Id_Number;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 16:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540099#M16632</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2019-03-04T16:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in all tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540108#M16633</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What your trying is not allowed, perhaps you can try an alternative way using dictionary tables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select cats(name, '=', tranwrd(name,'Table','ID_Number')) into: rename_vars separated by " "
from dictionary.columns
where libname='WORK' and memname='HAVE' and name like 'Table%';
quit;


data have;
set have(rename=(&amp;amp;rename_vars));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Mar 2019 17:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540108#M16633</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2019-03-04T17:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in all tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540110#M16635</link>
      <description>&lt;P&gt;The RENAME statement does not use variable lists, so it will not recognize TABLE: .&amp;nbsp; Even if the list would only generate one name.&lt;/P&gt;
&lt;P&gt;If it is as simple as your sample then just use code generation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call execute('proc datasets lib=mylib nolist;');
  do i=1 to 50;
     call execute(cats('modify mylib.dataset',i,';'));
     call execute(cats('rename table',i,'=ID_number;run;'));
  end;
  call execute('quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then use&amp;nbsp;metadata to generate the data needed to generate the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  create table rename as
     select libname,memname,name,'ID_Number' as new_name
     from dictionary.columns
     where upcase(name) like 'TABLE%'
     order by 1,2
  ;
quit;
filename code temp;
data _null_;
  set rename ;
  by libname memname;
  if first.libname then put 'proc datasets nolist lib=' libname ';' ;
  if not (first.memname and last.memname) then 
    putlog 'ERROR: Duplicate fields in ' libname= memname= name=
  ;
  else do;
    put 'modify ' memname ';rename ' name '=' new_name ';run;' ;
  end;
  if last.libname then put 'quit;';
run;
%include code ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2019 17:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540110#M16635</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-04T17:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in all tables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540123#M16637</link>
      <description>Thank you so much. It worked</description>
      <pubDate>Mon, 04 Mar 2019 17:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Rename-variables-in-all-tables/m-p/540123#M16637</guid>
      <dc:creator>AZIQ1</dc:creator>
      <dc:date>2019-03-04T17:43:30Z</dc:date>
    </item>
  </channel>
</rss>

