<?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: Rename all 550 variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593207#M15489</link>
    <description>&lt;P&gt;This should get you started. In the PROC SQL put the library name and dataset name, &lt;STRONG&gt;in upper case, &lt;/STRONG&gt;where I show LIB and DATASET. This extracts the names of the variables if they actually start with VAR. The data set is used to create proc datasets rename statement. Make sure to use the same library and dataset names that you did in the Proc SQL step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.rename as
   select name, cats(name,'_chg') as newname
   from dictionary.columns
   where libname='LIB' and memname='DATASET'
   and upcase(name) like 'VAR%'
   ;
quit;

data _null_;
   set work.rename end=LastName;
   if _n_ = 1 then do;
      /* LIB and DATASET below are the library and data set name used above*/
      Call execute ("Proc datasets library=LIB nodetails nolist;");
      Call execute ("modify DATASET;");
      Call execute ("rename ")  ;
   end;
   Call execute(catx(' ',name,' = ',newname)) ;
   if LastName then do;
      Call execute (";") ;
      Call execute ("quit;");
   end;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Oct 2019 20:53:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-10-01T20:53:45Z</dc:date>
    <item>
      <title>Rename all 550 variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593201#M15485</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset contains 551 variables (ID, var1, var2, var3.....var550). I would like to rename all the var1-var550 with a "_chg" at the end (var1_chg, var2_chg,......var550_chg). What's the best way to rename all 550 variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 20:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593201#M15485</guid>
      <dc:creator>Denali</dc:creator>
      <dc:date>2019-10-01T20:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all 550 variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593204#M15486</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140136"&gt;@Denali&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Your sample HAVE*/
data have;
 array col(550);
run;
/*Rename*/
data _null_;
 if 0 then set have;
 array c col:;
 call execute('proc datasets lib=work; modify have;rename');
do over c;
  call execute(cats(vname(c),'=',vname(c),'_chg  '));
end;
 call execute(';quit;');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course you can query dictionary columns /sashelp vcolumns and get the same . I just fancied something of the above kind&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 20:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593204#M15486</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-01T20:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all 550 variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593206#M15488</link>
      <description>&lt;P&gt;This is a common request.&amp;nbsp; The strategy is to (1) get the metadata (in this case all the variable names, each followed by and equal sign and a corresponding new variable name) into a macro variable,&amp;nbsp; Then include this macrovar in a rename statement in a PROC DATASETS, as in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  array v {500} var1-var500;
  do _n_=1 to dim(v);  v{_n_}=_n_; end;
  output;
  stop;
run;

proc sql noprint;
  select 
    cats(name,'=',name,'_chg')
   into :rename_list separated by ' '
  from dictionary.columns where libname='WORK' and memname='HAVE';
quit;


proc datasets library=work nolist;
  modify have;
  rename &amp;amp;rename_list ;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a number of metadata resource in various members of the DICTIONARY container, which is accessible only via&amp;nbsp;a proc sql.&amp;nbsp;This particular members here is&amp;nbsp;COLUMNS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards,&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 20:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593206#M15488</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-01T20:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all 550 variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593207#M15489</link>
      <description>&lt;P&gt;This should get you started. In the PROC SQL put the library name and dataset name, &lt;STRONG&gt;in upper case, &lt;/STRONG&gt;where I show LIB and DATASET. This extracts the names of the variables if they actually start with VAR. The data set is used to create proc datasets rename statement. Make sure to use the same library and dataset names that you did in the Proc SQL step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table work.rename as
   select name, cats(name,'_chg') as newname
   from dictionary.columns
   where libname='LIB' and memname='DATASET'
   and upcase(name) like 'VAR%'
   ;
quit;

data _null_;
   set work.rename end=LastName;
   if _n_ = 1 then do;
      /* LIB and DATASET below are the library and data set name used above*/
      Call execute ("Proc datasets library=LIB nodetails nolist;");
      Call execute ("modify DATASET;");
      Call execute ("rename ")  ;
   end;
   Call execute(catx(' ',name,' = ',newname)) ;
   if LastName then do;
      Call execute (";") ;
      Call execute ("quit;");
   end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Oct 2019 20:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593207#M15489</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-01T20:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rename all 550 variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593208#M15490</link>
      <description>&lt;P&gt;If you're willing to change the name slightly this can be a one liner.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rename var1-var550 = var_chg_1-var_chg_550;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/140136"&gt;@Denali&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset contains 551 variables (ID, var1, var2, var3.....var550). I would like to rename all the var1-var550 with a "_chg" at the end (var1_chg, var2_chg,......var550_chg). What's the best way to rename all 550 variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 20:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-all-550-variables/m-p/593208#M15490</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-01T20:58:40Z</dc:date>
    </item>
  </channel>
</rss>

