<?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: SAS rename variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684544#M207463</link>
    <description>&lt;P&gt;If you go through the trouble of creating a macro variable to do this, then the much more efficient way of renaming variables is using PROC DATASETS rather than doing all the input and output of reading the (possibly very large) data set again just to perform a rename.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2020 10:37:14 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-17T10:37:14Z</dc:date>
    <item>
      <title>SAS rename variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684387#M207387</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have got the following variables: A_BC_1, A_BC_2, A_BC_3 and it continues to A_BC_120 (i.e. A_BC_1 - A_BC_120). Can someone help me rename all of these 120 variables in a more efficient way, so that they are called "eq1, eq2, eq3 and all the way to eq120 (i.e. eq1 - eq120)? Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Manually writing the code would be:&lt;/P&gt;
&lt;P&gt;data final;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set initial (rename=(A_BC_1=eq1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A_BC_2=eq2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A_BC_3=eq3&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (continues all the way to eq120)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;A_BC_120=eq120 ) );&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 21:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684387#M207387</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2020-09-16T21:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rename variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684390#M207389</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    rename a_bc_1-a_bc_120=eq1-eq120;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is somewhat inefficient for HUGE data sets, but it works.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 21:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684390#M207389</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-16T21:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rename variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684406#M207394</link>
      <description>&lt;P&gt;Probably the easiest way is to use a variable list notation like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data final;
set initial(rename=(A_BC_1 - A_BC_120 = eq1 - eq120));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you could also make it a little more complicated to impress your co-workers and add an extra data step that creates a macro variable, which can be used in the set statement. Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length dummy_var $5000;
do n=1 to 120;
   dummy_var = catx(' ',dummy_var,'A_BC_'||left(put(n,3.)),'=eq'||left(put(n,3.)));
end;
call symput('renamelist',dummy_var);
stop;
run;
data final;
set initial(rename=(&amp;amp;renamelist));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It first defines a character variable of sufficient length. then it adds in a do loop all necessary rename pairs. Upon completion it uses the call symput routine to put that string into the macro variable renamelist, which is later referenced in the set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 22:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684406#M207394</guid>
      <dc:creator>ErikT</dc:creator>
      <dc:date>2020-09-16T22:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rename variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684544#M207463</link>
      <description>&lt;P&gt;If you go through the trouble of creating a macro variable to do this, then the much more efficient way of renaming variables is using PROC DATASETS rather than doing all the input and output of reading the (possibly very large) data set again just to perform a rename.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 10:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684544#M207463</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-17T10:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS rename variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684614#M207495</link>
      <description>&lt;P&gt;It all depends on what has to be done with the variables. If it is just renaming and nothing else, I agree that using&amp;nbsp; PROC DATASETS for the rename is much more efficient. But if you have to have a data step anyway for some re-coding or calculations, then the rename in the SET statement makes sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: there is a difference between the separate RENAME statement and the rename option in the SET statement. Both variants were proposed in previous posts. The RENAME statement works on the &lt;U&gt;output&lt;/U&gt; data set, so for actions within the data step you have to use the old names. The rename option in the SET statement works on the &lt;U&gt;input&lt;/U&gt;. So you can use the new names in the data step.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 14:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-rename-variables/m-p/684614#M207495</guid>
      <dc:creator>ErikT</dc:creator>
      <dc:date>2020-09-17T14:09:42Z</dc:date>
    </item>
  </channel>
</rss>

