<?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 variables at one time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675934#M203730</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 500 variables in a dataset (some character and numeric) and I want to rename them all sequentially as var1-var500. Is there an efficient way to do this? Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but it will involve getting the list of existing variables in the order you want first.&lt;/P&gt;
&lt;P&gt;Example of code that you would want:&lt;/P&gt;
&lt;PRE&gt;proc datasets library=somelib;
  modify datasetname;
  rename thisvar=var1
         thatvar=var2
         othervar=var3
  ;
run;
quit;&lt;/PRE&gt;
&lt;P&gt;If you want to rename them in the order they currently appear in the data set you can get the list of variables and the order a couple of ways to create the new var. An example you can examine results:&lt;/P&gt;
&lt;PRE&gt;proc contents data=sashelp.class out=work.classlist noprint;
run;

data want;
   set work.classlist (keep= name  varnum);
   length newvar $ 32;
   newvar= catt('var',varnum);&lt;BR /&gt;   file print;&lt;BR /&gt;   put name '=' newvar;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;The data step will write to the results window a list of names that you could use in the example rename. Use your data set library and name of course to make sense for your purpose.&lt;/P&gt;
&lt;P&gt;If you need the variables renamed in another then you will need to describe what that order must be.&lt;/P&gt;
&lt;P&gt;Hint: if you cant get the example work.classlist to sort as desired this is going to be a bit tricky and may require just writing the 500 rename pairs by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help though to explain why this is needed. Perhaps we can present another solution or prevention tip.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Aug 2020 15:51:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-08-11T15:51:54Z</dc:date>
    <item>
      <title>rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675928#M203725</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 500 variables in a dataset (some character and numeric) and I want to rename them all sequentially as var1-var500. Is there an efficient way to do this? Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 15:31:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675928#M203725</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-08-11T15:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675931#M203727</link>
      <description>&lt;P&gt;This suggestion works well&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Rename-all-variables/m-p/500828#M133408" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Rename-all-variables/m-p/500828#M133408&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 15:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675931#M203727</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-08-11T15:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675932#M203728</link>
      <description>&lt;P&gt;SASHELP.VCOLUMN + PROC DATASETS + CALL EXECUTE&lt;/P&gt;
&lt;P&gt;1. Gets you the list of variables in the order&lt;/P&gt;
&lt;P&gt;2. Renames your variables&lt;/P&gt;
&lt;P&gt;3. Controls the code overall.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace the two occurences of myDataset with your data set name and the appropriate library name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _new_list;
 set sashelp.vtable 
    (where=(upcase(libname)='WORK' and upcase(memname) = "MYDATASET")) end=eof;
 *filter list for only tables of interest;
 
 
 *start proc datasets;
 if _n_=1 then
    call execute ('proc datasets lib=WORK nodetails nolist; modify myDataset; rename ');
    
 *add on new name calculation;
 new_name=catt('Name', put(_n_, z3.));
 
 *pass new and old name to proc datasets;
 call execute (name);
 call execute ('=');
 call execute (new_name);
 
 *if last record then quit;
 If eof then
    call execute (';run;quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 500 variables in a dataset (some character and numeric) and I want to rename them all sequentially as var1-var500. Is there an efficient way to do this? Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675932#M203728</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-11T16:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675933#M203729</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
a=1;
b=2;
c="3";
d="4";
run;
title "Before";
proc print data = have;
run;

proc transpose data = have(obs=0) out = tmp(keep = _name_);
var _all_;
run;

proc sql;
  select _name_ || ' = var' || put(monotonic(), best. -L)
  into :renameList separated by " "
  from tmp;
run;

proc datasets lib = work nodetails nolist noprint;
  modify have;
    rename &amp;amp;renameList.;
  run;
quit;

title "After";
proc print data = have;
run;

title;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 15:49:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675933#M203729</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-08-11T15:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675934#M203730</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 500 variables in a dataset (some character and numeric) and I want to rename them all sequentially as var1-var500. Is there an efficient way to do this? Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, but it will involve getting the list of existing variables in the order you want first.&lt;/P&gt;
&lt;P&gt;Example of code that you would want:&lt;/P&gt;
&lt;PRE&gt;proc datasets library=somelib;
  modify datasetname;
  rename thisvar=var1
         thatvar=var2
         othervar=var3
  ;
run;
quit;&lt;/PRE&gt;
&lt;P&gt;If you want to rename them in the order they currently appear in the data set you can get the list of variables and the order a couple of ways to create the new var. An example you can examine results:&lt;/P&gt;
&lt;PRE&gt;proc contents data=sashelp.class out=work.classlist noprint;
run;

data want;
   set work.classlist (keep= name  varnum);
   length newvar $ 32;
   newvar= catt('var',varnum);&lt;BR /&gt;   file print;&lt;BR /&gt;   put name '=' newvar;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;The data step will write to the results window a list of names that you could use in the example rename. Use your data set library and name of course to make sense for your purpose.&lt;/P&gt;
&lt;P&gt;If you need the variables renamed in another then you will need to describe what that order must be.&lt;/P&gt;
&lt;P&gt;Hint: if you cant get the example work.classlist to sort as desired this is going to be a bit tricky and may require just writing the 500 rename pairs by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help though to explain why this is needed. Perhaps we can present another solution or prevention tip.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 15:51:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675934#M203730</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-11T15:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675935#M203731</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It might help though to explain why this is needed. Perhaps we can present another solution or prevention tip.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, I agree. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;, why is this needed? Its hard for me to imagine this being of any benefit in any programming I have done.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 15:58:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675935#M203731</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T15:58:56Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675942#M203734</link>
      <description>I am writing an array to change the variables from yes/no to 1/0 and wanted to sequentially call the variables instead of listing all of them</description>
      <pubDate>Tue, 11 Aug 2020 16:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675942#M203734</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-08-11T16:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675943#M203735</link>
      <description>&lt;P&gt;There are many other ways to refer to variable lists. Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am writing an array to change the variables from yes/no to 1/0 and wanted to sequentially call the variables instead of listing all of them&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675943#M203735</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-11T16:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675949#M203740</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am writing an array to change the variables from yes/no to 1/0 and wanted to sequentially call the variables instead of listing all of them&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; beat me to it, but I'll say it anyway. None of this variable name changing is necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your variable names appear in the data set as AARDVARK ANTELOPE ARMADILLO ... ZEBRA, you don't have to type them all out, and you don't have to rename them to have names with consecutive numbers. You can refer to them all with the double-dash, such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array animals(*) aardvark--zebra;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or if the order is not alphabetical, they appear in your data set in some other order, such as GORILLA LION ZEBRA AARDVARK ... NARWHAL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then you refer to them in the order they appear in your data set as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array animals(*) gorilla--narwhal;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675949#M203740</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T16:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675950#M203741</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am writing an array to change the variables from yes/no to 1/0 and wanted to sequentially call the variables instead of listing all of them&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you don't want to actually change the names then just use an array.&amp;nbsp; Since you mentioned that you had numeric and character variables then perhaps two arrays?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  array _c _character_;
  array _n _numeric_;
  do over _c;
      if upcase(_c) in ('YES','Y','TRUE') then _c='YES'; 
      else _c='NO';
  end;
  do over _n;
     _n = (_n &amp;gt; 0);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps leave the variables as is and just use a format to display the values as YES or NO?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675950#M203741</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-11T16:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675956#M203742</link>
      <description>&lt;P&gt;Okay, I just did a search, and this is the first ever use of the word "aardvark" in the SAS Communities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm giving myself a gold star, and taking the rest of the day off! &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":raising_hands:"&gt;🙌&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675956#M203742</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T16:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: rename all variables at one time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675969#M203743</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194348"&gt;@GS2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I am writing an array to change the variables from yes/no to 1/0 and wanted to sequentially call the variables instead of listing all of them&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Another option might be to go back to how you read the data. You can create a custom informat that would read "yes" and "no" as 1 and 0. Read the data with the new informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue yesno (upcase)
'YES' = 1
'NO'  = 0
other = .
;

data example;
  informat x y z yesno.;
  input x y z;
datalines;
Yes no nO
yes NO No
yES yEs yeS
;
&lt;/PRE&gt;
&lt;P&gt;The upcase option on the invalue statement uses upper case text to compare to the values so minor issues like inconsistent capitalization are treated as, usually, desired for reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 17:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rename-all-variables-at-one-time/m-p/675969#M203743</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-11T17:48:53Z</dc:date>
    </item>
  </channel>
</rss>

