<?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: column rename macro in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493338#M31802</link>
    <description>&lt;P&gt;Can that macro, it's much easier in a simple data step with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

data _null_;
set sashelp.vcolumn (where=(libname = "WORK" and memname = "CLASS")) end=eof;
if _n_ = 1 then call execute("proc datasets lib=WORK nolist;modify CLASS; rename");
call execute(' ' !! trim(name) !! '=old_' !! trim(name));
if eof then call execute(';quit;');
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Sep 2018 10:02:36 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-09-07T10:02:36Z</dc:date>
    <item>
      <title>column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493320#M31798</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi all am trying to execute column rename for a large data set , am getting below error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;all is i am trying to all column names in different variables, and trying to rename .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro rename;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(*) into :n&lt;BR /&gt;from sashelp.vcolumn&lt;BR /&gt;where libname='WORK' and&lt;BR /&gt;memname='_VAR_OLD';&lt;BR /&gt;select distinct(name) into :var1-:var&amp;amp;n&lt;BR /&gt;from sashelp.vcolumn&lt;BR /&gt;where libname='WORK' and&lt;BR /&gt;memname='_VAR_OLD';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets libname='WORK' nolist;&lt;BR /&gt;modify _var_old;&lt;BR /&gt;rename&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%if %index(%upcase(&amp;amp;except), %upcase(&amp;amp;&amp;amp;var&amp;amp;i)) eq 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;&amp;amp;var&amp;amp;i=OLD_&amp;amp;var&amp;amp;i.&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend rename;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;NOTE: Line generated by the macro variable "N".&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;326 var 8&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;_&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;22&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;76&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR 22-322: Syntax error, expecting one of the following: ',', FROM, NOTRIM.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;NOTE: Line generated by the invoked macro "RENAME".&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;326 proc datasets libname='WORK' nolist; modify _var_old;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;_______ ______&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;1 22&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;200&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NOTE: Enter RUN; to continue or QUIT; to end the procedure.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;NOTE: Statements not processed because of errors noted above.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;WARNING 1-322: Assuming the symbol LIB was misspelled as libname.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Apparent symbolic reference VAR1 not resolved.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NOTE 138-205: Line generated by the macro variable "I".&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;326 OLD_&amp;amp;var1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;_&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;22&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR 22-322: Expecting a name. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 09:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493320#M31798</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2018-09-07T09:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493323#M31799</link>
      <description>&lt;P&gt;Indirect addressing of macro variables needs a double ampersand.&lt;/P&gt;
&lt;P&gt;To get the contents of &amp;amp;var6 when &amp;amp;i=6, use &amp;amp;&amp;amp;var&amp;amp;i&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 09:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493323#M31799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-07T09:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493324#M31800</link>
      <description>&lt;P&gt;Thanks for quick help, am trying to execute the below code , but still can't able to resolve the variable&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro rename;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(*) into :n&lt;BR /&gt;from sashelp.vcolumn&lt;BR /&gt;where libname='WORK' and&lt;BR /&gt;memname='_VAR_OLD';&lt;BR /&gt;select distinct(name) into :var1-:var&amp;amp;n&lt;BR /&gt;from sashelp.vcolumn&lt;BR /&gt;where libname='WORK' and&lt;BR /&gt;memname='_VAR_OLD';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc datasets libname='WORK' nolist;&lt;BR /&gt;modify _var_old;&lt;BR /&gt;rename&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;BR /&gt;%if %index(%upcase(&amp;amp;except), %upcase(&amp;amp;&amp;amp;var&amp;amp;i)) eq 0 %then&lt;BR /&gt;%do;&lt;BR /&gt;&amp;amp;&amp;amp;var&amp;amp;i=OLD_&amp;amp;&amp;amp;var&amp;amp;i.&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%mend rename;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 09:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493324#M31800</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2018-09-07T09:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493330#M31801</link>
      <description>&lt;P&gt;Please post test data in the form of a datastep, and what the output should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, we had more or less exactly the same question yesterday:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492959#M129654" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/how-to-select-rows-with-column-value-not-in-a-macro-list/m-p/492959#M129654&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Sep 2018 09:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493330#M31801</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-07T09:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493338#M31802</link>
      <description>&lt;P&gt;Can that macro, it's much easier in a simple data step with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
set sashelp.class;
run;

data _null_;
set sashelp.vcolumn (where=(libname = "WORK" and memname = "CLASS")) end=eof;
if _n_ = 1 then call execute("proc datasets lib=WORK nolist;modify CLASS; rename");
call execute(' ' !! trim(name) !! '=old_' !! trim(name));
if eof then call execute(';quit;');
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Sep 2018 10:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493338#M31802</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-07T10:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493347#M31806</link>
      <description>&lt;P&gt;You've got a few problems:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;select count(*) into :n&amp;nbsp; will have leading blanks in the macro var N which cause problems.&amp;nbsp; Change to :&amp;nbsp;select count(*) into :n trimmed.&amp;nbsp; TRIMMED will get rid of leading and trailing blanks.&amp;nbsp; The easiest way to detect such blanks is with %put &amp;gt;&amp;gt;&amp;amp;n&amp;lt;&amp;lt;;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;proc datasets libname='WORK' nolist;&amp;nbsp; The option is library= not libname=, and the value should not be in quotes.&amp;nbsp; Change to:&amp;nbsp;proc datasets library=WORK nolist;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;There are also general macro design issues.&amp;nbsp; Your macro has no parameters, I'm guessing you would want parameters for name of the the library, datasest, except, etc.&amp;nbsp; It's a good idea to declare macro variables to be %local, so they don't collide with macro variables from another scope.&amp;nbsp; This is a hassle when working with "macro arrays" but still worth while.&amp;nbsp; You can do stuff like: %do i=1 %to &amp;amp;n ; %local var&amp;amp;i; %end ;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 07 Sep 2018 10:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493347#M31806</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-09-07T10:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: column rename macro</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493393#M31807</link>
      <description>Thanks for that , can able to customise solution&lt;BR /&gt;&lt;BR /&gt;proc contents data=_Test_old&lt;BR /&gt;out=_var_old(keep = memname memlabel name label format length type varnum)&lt;BR /&gt;noprint order=collate;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table _var_old as&lt;BR /&gt;select name ,strip(name)||'_O' as OLD_name&lt;BR /&gt;from _var_old&lt;BR /&gt;;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;select catt(strip(name),"=",strip(OLD_name))&lt;BR /&gt;into :renames separtated by " "&lt;BR /&gt;from _var_old&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;BR /&gt;data _Test_old_1;&lt;BR /&gt;set _Test_old (rename=(&amp;amp;renames.));&lt;BR /&gt;run;</description>
      <pubDate>Fri, 07 Sep 2018 13:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/column-rename-macro/m-p/493393#M31807</guid>
      <dc:creator>learn_SAS_23</dc:creator>
      <dc:date>2018-09-07T13:03:31Z</dc:date>
    </item>
  </channel>
</rss>

