<?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: How to rename a wide amount of variables with forbidden characters in their names? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377790#M90735</link>
    <description>&lt;P&gt;Both of your codes worked to solve my issue, my thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jul 2017 14:32:56 GMT</pubDate>
    <dc:creator>saslamber</dc:creator>
    <dc:date>2017-07-20T14:32:56Z</dc:date>
    <item>
      <title>How to rename a wide amount of variables with forbidden characters in their names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/376617#M90414</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have a table (named tabletest)&amp;nbsp;with lots of variables (too numerous to be renamed one by one, for instance variables named&amp;nbsp;a-1... a-10, ..., z-1... z-10, a, ..., z)&amp;nbsp;whose names may have invalid characters (for instance an-1, which was coded as 'an-1'n to be accepted). My aim is to rename all these variables with invalid characters (we can assume - is the only one), by replacing the invalid characters&amp;nbsp;by Z.&lt;/P&gt;&lt;P&gt;I figured I would first get the list of the names of all variables from my table by exporting the result of a proc contents in a table named&amp;nbsp;listname (where I only kept the names).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can use tranwrd (for instance name = TRANWRD(name, '-', 'Z') ; in a data set) to rename all elements of my list of variables listname. However,&amp;nbsp;I do not know how to rename all the variables of tabletest that appear to have a - in their name.&lt;/P&gt;&lt;P&gt;I tried what you can see below, but it didn't work because temp1 isn't a variable of tabletest in my code, only the values it takes&amp;nbsp;are ones.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA tabletest ;
  INPUT 'an-1'n 'an-2'n 'an-3'n 'an-4'n 'an-5'n 'an-6'n 'an-7'n 'an-8'n b c d e ;
  CARDS ;
1 3 5 7 9 11 13 15 17 19 21 23
2 4 6 8 10 12 14 16 18 20 22 24
;
RUN ;

DATA listname ;
INPUT name : $40. ;
CARDS ;
an-1
an-2
an-3
an-4
an-5
an-6
an-7
an-8
b
c
d
e
;
RUN ;

DATA _NULL_ ;
SET listname ;
temp1 = name ;
temp2 = TRANWRD(name, '-', 'Z') ;
IF temp2 NE temp1 THEN CALL execute('PROC DATASETS LIBRARY = work ; MODIFY tabletest ; RENAME temp1 = temp2 ;') ;
RUN ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What could I do to fix that issue?&lt;/P&gt;&lt;P&gt;Thanks in advance for any proposal.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 15:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/376617#M90414</guid>
      <dc:creator>saslamber</dc:creator>
      <dc:date>2017-07-17T15:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a wide amount of variables with forbidden characters in their names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377099#M90536</link>
      <description>&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select "'"||name||"'n",TRANWRD(name, '-', 'Z') into :name,:newname&lt;BR /&gt;from dictionary.columns&lt;BR /&gt;where upcase(libname)='WORK' and lowcase(memname)='tabletest' and name like '%-%';&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;PROC DATASETS LIBRARY = work ; MODIFY tabletest ; RENAME &amp;amp;name = &amp;amp;newname ;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 19:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377099#M90536</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2017-07-18T19:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a wide amount of variables with forbidden characters in their names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377158#M90548</link>
      <description>&lt;P&gt;Or to rename them all:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select catt("'",NAME,"'n=",tranwrd(NAME,'-','Z')) into :rename separated by ' '
  from DICTIONARY.COLUMNS
  where LIBNAME='WORK' and MEMNAME='TABLETEST' and NAME contains '-';
quit;
                                                                          
proc datasets noprint ; modify TABLETEST ; rename &amp;amp;rename. ; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2017 01:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377158#M90548</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-19T01:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename a wide amount of variables with forbidden characters in their names?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377790#M90735</link>
      <description>&lt;P&gt;Both of your codes worked to solve my issue, my thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2017 14:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-a-wide-amount-of-variables-with-forbidden/m-p/377790#M90735</guid>
      <dc:creator>saslamber</dc:creator>
      <dc:date>2017-07-20T14:32:56Z</dc:date>
    </item>
  </channel>
</rss>

