<?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: Renaming multiple variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885599#M349964</link>
    <description>Thanks! Its working. Could you please tell me the purpose of  referring to sashelp.vcolumn ?</description>
    <pubDate>Thu, 20 Jul 2023 12:39:33 GMT</pubDate>
    <dc:creator>dac_js</dc:creator>
    <dc:date>2023-07-20T12:39:33Z</dc:date>
    <item>
      <title>Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885555#M349942</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following dataset:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input ID Var1 Var2 Var3new Var4new Var5old Var6old;&lt;BR /&gt;datalines;&lt;BR /&gt;1 11 12 13 14 15&lt;BR /&gt;16 2 21 22 23 24&lt;BR /&gt;25 26 3 31 32 33&lt;BR /&gt;34 35 36 4 41 42&lt;BR /&gt;43 44 45 46 5 56&lt;BR /&gt;51 52 53 54 55 56 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First I want a dataset after dropping all variables with names ending with "old" from the dataset (Var5old, Var6old) and in the new dataset I want to rename the variables where column name ends with "new" (Var3new, Var4new as Var3 Var4). As I have 100s of variables do not want to manually rename all of them. I am looking for a final dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input ID Var1 Var2 Var3 Var4;&lt;BR /&gt;datalines;&lt;BR /&gt;1 11 12 13&lt;BR /&gt;16 2 21 22&lt;BR /&gt;25 26 3 31&lt;BR /&gt;34 35 36 4&lt;BR /&gt;43 44 45 46&lt;BR /&gt;51 52 53 54&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 03:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885555#M349942</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-07-20T03:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885568#M349950</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vcolumn end=done;
where libname = "WORK" and memname = "HAVE";
length renamestr dropstr $32767;
retain renamestr dropstr;
if upcase(substr(name,length(name)-2)) = "OLD" then dropstr = catx(" ",dropstr,name);
if upcase(substr(name,length(name)-2)) = "NEW" then renamestr = catx(" ",renamestr,catx("=",name,substr(name,1,length(name)-3)));
if done
then do;
  call symputx("renamestr",renamestr);
  call symputx("dropstr",dropstr);
end;
run;

data want;
set have;
drop &amp;amp;dropstr.;
rename &amp;amp;renamestr.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 06:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885568#M349950</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-20T06:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885571#M349951</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
   set sashelp.vcolumn end=last;
   where libname eq 'WORK' and memname eq 'HAVE';
   if _N_ eq 1 then call execute('DATA want; set have;');
   if prxmatch('/old\s*$/i',name) then call execute('drop '||name||';');
   if prxmatch('/.+new\s*$/i',name) then call execute(catx(' ','rename',name,'=',substrn(name,1,lengthn(name)-3),';'));
   if last then call execute('run;');
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jul 2023 07:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885571#M349951</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-07-20T07:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885599#M349964</link>
      <description>Thanks! Its working. Could you please tell me the purpose of  referring to sashelp.vcolumn ?</description>
      <pubDate>Thu, 20 Jul 2023 12:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885599#M349964</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-07-20T12:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885600#M349965</link>
      <description>Thank you. Your code is working.</description>
      <pubDate>Thu, 20 Jul 2023 12:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885600#M349965</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-07-20T12:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885603#M349966</link>
      <description>&lt;P&gt;SASHELP.VCOLUMN is a SQL view using the pseudo-table DICTIONARY.COLUMNS (which itself is a dynamically created view of all variables in all datasets/views in all currently assigned libraries).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/n02s19q65mw08gn140bwfdh7spx7.htm" target="_blank" rel="noopener"&gt;documentation of the DICTIONARY tables&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jul 2023 13:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885603#M349966</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-20T13:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Renaming multiple variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885613#M349970</link>
      <description>Thank you Kurt!</description>
      <pubDate>Thu, 20 Jul 2023 13:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Renaming-multiple-variable-names/m-p/885613#M349970</guid>
      <dc:creator>dac_js</dc:creator>
      <dc:date>2023-07-20T13:37:56Z</dc:date>
    </item>
  </channel>
</rss>

