<?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 columns without knowing original column name but its labels. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351984#M23217</link>
    <description>&lt;P&gt;Fixed the problem by changing the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('proc datasets data=work.sample noprint nolist;');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('data work.sample_final; set work.sample;');&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 02:39:57 GMT</pubDate>
    <dc:creator>ayin</dc:creator>
    <dc:date>2017-04-21T02:39:57Z</dc:date>
    <item>
      <title>Rename columns without knowing original column name but its labels.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351975#M23214</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Have:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;column&amp;nbsp;reference table (named 'Col_Ref'), that looks like -&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Standard Label
Col_1    Are you kidding
Col_2    How to do it&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dataset (named 'sample'), that looks like -&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a1  a2  /* the label for a1 is 'Are you kidding', and for a2 is 'How to do it' */
3   char&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Want:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;rename the columns in the dataset 'sample' to:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Col_1 Col_2
3     char&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Note:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To generate the datasets:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Col_Ref;
	input Standard $ Label $char20.; 
cards;
Col_1 Are you kidding
Col_2 How to do it
;
run;

data sample;
	input a1 a2 $;
	label	a1 = 'Are you kidding'
		a2 = 'How to do it';
cards;
3 char
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To get a "reference" table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select name, label from sashelp.vcolumn
where upcase(libname) = 'WORK' and upcase(memname) = 'SAMPLE';

create table test2 as
select a.*,b.Standard from test a
left join Col_Ref b
on a.label = b.Label;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To rename using the "reference table":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set test2 end=last;
if _n_=1 then call execute('proc datasets data=work.sample noprint nolist;');
call execute(cat('rename ',strip(name),'=',strip(standard),';'));
if last then call execute(';run;quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Questions:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It is reporting an error:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1         + proc datasets data=work.sample noprint nolist;
                          ____
                          22
                          202
NOTE: Enter RUN; to continue or QUIT; to end the procedure.
ERROR 22-322: Syntax error, expecting one of the following: ;, ALTER, DD, DDNAME, DETAILS, FORCE, GENNUM, KILL, LIB, LIBRARY, 
              MEMTYPE, MT, MTYPE, NODETAILS, NOFS, NOLIST, NOPRINT, NOWARN, PROTECT, PW, READ.  
ERROR 202-322: The option or parameter is not recognized and will be ignored.
2         + rename a1=Col_1;
3         + rename a2=Col_2;
4         + ;run;

NOTE: Statements not processed because of errors noted above.
4         +      quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How to fix it?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 02:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351975#M23214</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-04-21T02:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns without knowing original column name but its labels.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351981#M23215</link>
      <description>&lt;P&gt;It should be&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work noprint nolist;
  modify sample;
 rename a1=Col_1;
 rename a2=Col_2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 02:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351981#M23215</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-21T02:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns without knowing original column name but its labels.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351982#M23216</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* Find matching labels */
proc sql;
select catx("=", a.name, b.standard)
into :rename separated by " "
from 
    dictionary.columns as a inner join
    col_ref as b on a.label=b.label
where a.libname="WORK" and upcase(a.memname)="SAMPLE";
quit;

/* Rename variables */
data want;
set sample;
rename &amp;amp;rename;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 02:36:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351982#M23216</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-21T02:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns without knowing original column name but its labels.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351984#M23217</link>
      <description>&lt;P&gt;Fixed the problem by changing the code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('proc datasets data=work.sample noprint nolist;');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('data work.sample_final; set work.sample;');&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 02:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/351984#M23217</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-04-21T02:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns without knowing original column name but its labels.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/352244#M23250</link>
      <description>&lt;P&gt;Proc datasets wants a LIBRARY not a dataset on the proc statement and a MODIFY with the dataset name&amp;nbsp;before the rename/label etc.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 17:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Rename-columns-without-knowing-original-column-name-but-its/m-p/352244#M23250</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-21T17:05:31Z</dc:date>
    </item>
  </channel>
</rss>

