<?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 Rename columns when column names have special characters in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505604#M135419</link>
    <description>&lt;P&gt;I am trying to rename my columns in a macro&amp;nbsp;but my desired column names have spaces and special characters in them. (e.g. change column name aaa to aaa $)The code with nliteral works fine outside of the macro but when running in the macro it produces error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 24-322: Variable name is not valid.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My code is below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;&lt;BR /&gt;input name_old $3. name_new &amp;amp; $5.;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa aaa $&lt;BR /&gt;bbb bbb $&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%macro process;

PROC SQL;
SELECT cats(name_old,' = ',nliteral(name_new)) 
INTO :rename separated by ' '
FROM names;
quit;

data data2;
  SET data1 (rename=(&amp;amp;rename));
run;

%mend;

%process;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to write in the macro because I have to perform this action to proceed to my next desired output for multiple data sets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Oct 2018 15:17:33 GMT</pubDate>
    <dc:creator>qw213</dc:creator>
    <dc:date>2018-10-18T15:17:33Z</dc:date>
    <item>
      <title>Rename columns when column names have special characters in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505604#M135419</link>
      <description>&lt;P&gt;I am trying to rename my columns in a macro&amp;nbsp;but my desired column names have spaces and special characters in them. (e.g. change column name aaa to aaa $)The code with nliteral works fine outside of the macro but when running in the macro it produces error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR 24-322: Variable name is not valid.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My code is below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;&lt;BR /&gt;input name_old $3. name_new &amp;amp; $5.;&lt;BR /&gt;datalines;&lt;BR /&gt;aaa aaa $&lt;BR /&gt;bbb bbb $&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%macro process;

PROC SQL;
SELECT cats(name_old,' = ',nliteral(name_new)) 
INTO :rename separated by ' '
FROM names;
quit;

data data2;
  SET data1 (rename=(&amp;amp;rename));
run;

%mend;

%process;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I need to write in the macro because I have to perform this action to proceed to my next desired output for multiple data sets.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for your help!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 15:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505604#M135419</guid>
      <dc:creator>qw213</dc:creator>
      <dc:date>2018-10-18T15:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns when column names have special characters in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505608#M135421</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241069"&gt;@qw213&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you set the required system option?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Oct 2018 15:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505608#M135421</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-18T15:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Rename columns when column names have special characters in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505612#M135425</link>
      <description>&lt;P&gt;Ah yes that's the issue I had preset it to V7 in the previous step. Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 15:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-columns-when-column-names-have-special-characters-in/m-p/505612#M135425</guid>
      <dc:creator>qw213</dc:creator>
      <dc:date>2018-10-18T15:37:18Z</dc:date>
    </item>
  </channel>
</rss>

