<?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 only part of variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/599898#M173270</link>
    <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thank you. I do have more than 1.000 variables but I could subset the files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try doing that and see what I get. I have used macro variables before so I should be able to do what you suggested (put the list into a single macro variable) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2019 18:44:32 GMT</pubDate>
    <dc:creator>Mscarboncopy</dc:creator>
    <dc:date>2019-10-28T18:44:32Z</dc:date>
    <item>
      <title>How to rename only part of variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598775#M172713</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I need to rename a lot of variables that share part of a name, s seen in the example below.&lt;/P&gt;&lt;P&gt;The Xs here are all different words for each variable name in the data set, they do not match.&lt;/P&gt;&lt;P&gt;The renaming would be only adding a number to the first part of the common (shared) name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ppa&lt;/STRONG&gt;50XXXXXX&lt;/P&gt;&lt;P&gt;and I need them all to be&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;pp02a&lt;/STRONG&gt;50XXXXXX&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did not want to do an array, if there is a more simple way to do this, without having to list each single variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 16:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598775#M172713</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-23T16:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename only part of variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598778#M172715</link>
      <description>&lt;P&gt;You will need to list all of the variables.&amp;nbsp; But you can use a program to make the list for you.&lt;/P&gt;
&lt;P&gt;If the list is short (less than 1000 variables) then you can just put the list into a single macro variable (limit 64K bytes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say you have a dataset named WORK.HAVE that you want to rename the variables for.&amp;nbsp; First get the list of variables, find the ones that match your pattern, generate the new name and then produce a string of OLD=NEW pairs that can be used in a rename statement (or rename= dataset option).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=work.have out=contents noprint ; run;

proc sql noprint;
select catx('=',name,'ppa02a50'||substr(name,6))
  into :renames separated by ' '
  from contents
  where upcase(name) like 'PPA50%'
;
quit;

proc datasets nolist lib=WORK;
  modify have ;
    rename &amp;amp;renames;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your dataset has non-standard names (allowed when VALIDVARNAME option is set to ANY) then include calls to the NLITERAL() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;catx('=',nliteral(name),nliteral('ppa02a50'||substr(name,6)))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Oct 2019 17:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598778#M172715</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-23T17:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename only part of variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598848#M172748</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I need to rename a lot of variables that share part of a name, s seen in the example below.&lt;/P&gt;
&lt;P&gt;The Xs here are all different words for each variable name in the data set, they do not match.&lt;/P&gt;
&lt;P&gt;The renaming would be only adding a number to the first part of the common (shared) name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ppa&lt;/STRONG&gt;50XXXXXX&lt;/P&gt;
&lt;P&gt;and I need them all to be&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;pp02a&lt;/STRONG&gt;50XXXXXX&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I did not want to do an array, if there is a more simple way to do this, without having to list each single variable.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you in advance.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Before you turn any automated renaming process loose on variables when the new names would be longer than the old ones you should verify that none of the lengths of the current variable names plus the count of new characters would exceed 32 characters.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2019 21:43:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/598848#M172748</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-23T21:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename only part of variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/599898#M173270</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thank you. I do have more than 1.000 variables but I could subset the files.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try doing that and see what I get. I have used macro variables before so I should be able to do what you suggested (put the list into a single macro variable) .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 18:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/599898#M173270</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-28T18:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to rename only part of variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/599899#M173271</link>
      <description>&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 18:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rename-only-part-of-variable-names/m-p/599899#M173271</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2019-10-28T18:45:28Z</dc:date>
    </item>
  </channel>
</rss>

