<?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 how to rename variable names in batch, maybe using array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511815#M137752</link>
    <description>&lt;P&gt;Hi Dear all, I have a question, I want to&amp;nbsp; create a new list of variables x_a, y_a, and z_a, based on the values of variables x, y, and z. &amp;nbsp;How can we achieve this in array &lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;in batch&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;? because rather than for 3 variables, I want to do this for 20 variables. I'm just giving a simplified example here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ZERO(*)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x&lt;/P&gt;&lt;P&gt;y&lt;/P&gt;&lt;P&gt;z&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dim(ZERO);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ZERO(i)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; [some function that creates a new variable by adding _a to A(i)]=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.A&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;can anyone fill in the brackets &lt;FONT face="Courier New"&gt;[some function that creates a new variable name by adding _a to the variable name that corresponds to ZERO(i)]?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;Thanks a lot!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Nov 2018 20:07:23 GMT</pubDate>
    <dc:creator>changxuosu</dc:creator>
    <dc:date>2018-11-09T20:07:23Z</dc:date>
    <item>
      <title>how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511815#M137752</link>
      <description>&lt;P&gt;Hi Dear all, I have a question, I want to&amp;nbsp; create a new list of variables x_a, y_a, and z_a, based on the values of variables x, y, and z. &amp;nbsp;How can we achieve this in array &lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;in batch&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;? because rather than for 3 variables, I want to do this for 20 variables. I'm just giving a simplified example here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ZERO(*)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x&lt;/P&gt;&lt;P&gt;y&lt;/P&gt;&lt;P&gt;z&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dim(ZERO);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ZERO(i)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; [some function that creates a new variable by adding _a to A(i)]=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;.A&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;can anyone fill in the brackets &lt;FONT face="Courier New"&gt;[some function that creates a new variable name by adding _a to the variable name that corresponds to ZERO(i)]?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New"&gt;Thanks a lot!&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511815#M137752</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2018-11-09T20:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511826#M137754</link>
      <description>There isn't some function that does this that easily. If you want to rename it's easier to write the rename statements...for 20 that's not too bad. If you ahve sequences that are numeric this is super easy:&lt;BR /&gt;&lt;BR /&gt;Rename name1-name3 = new_name1-new_name3;&lt;BR /&gt;&lt;BR /&gt;However, suffixes are more work. You can use an array though if you watned. &lt;BR /&gt;&lt;BR /&gt;array new(*) var1_a var2_a var3_a ....var20_a;*you'll have to list them all;&lt;BR /&gt;&lt;BR /&gt;if zero(i) = 0 then new(i) = .A;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511826#M137754</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-09T20:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511828#M137755</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/193702"&gt;@changxuosu&lt;/a&gt;&amp;nbsp;: Do you want to create new columns with no values populated (blank )&amp;nbsp; and the name of the new columns should be based on the values of your existing dataset ? How many observations does your input dataset has&amp;nbsp;?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511828#M137755</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-09T20:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511832#M137757</link>
      <description>&lt;P&gt;Or this method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
proc sql noprint;
select catx(' = ', name, catt(name, '_a')) 
into :rename_list separated by " "
from sashelp.vcolumn
where libname='SASHELP' and memname='CLASS';
quit;

data class;
set sashelp.class;
rename &amp;amp;rename_list.;
run;

proc contents data=class;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Nov 2018 20:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511832#M137757</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-09T20:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511876#M137776</link>
      <description>&lt;P&gt;Perhaps the current replies are barking up the wrong tree.&amp;nbsp; Your question doesn't really ask to rename variables.&amp;nbsp; It talks about creating a new variable based on the original variable.&amp;nbsp; While macros can come up with the new names, it's easier to type them out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array old {20} x y z .......;&lt;/P&gt;
&lt;P&gt;array new {20} x_a y_a z_a .........;&lt;/P&gt;
&lt;P&gt;do k=1 to dim(old);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if old{k}=0 then new{k} = .a;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you were going to attempt this the hard way, these are the pieces that you would need in your macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;a parameter to indicate the suffix:&amp;nbsp; _a&lt;/P&gt;
&lt;P&gt;a parameter to list the original names:&amp;nbsp; x y z .........&lt;/P&gt;
&lt;P&gt;use the list of the original names within the macro to populate one array:&lt;/P&gt;
&lt;P&gt;array old {*} &amp;amp;original_names;&lt;/P&gt;
&lt;P&gt;logic to populate the new array with a list of names that includes the suffix, based on both incoming parameters&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;said, it's much easier to just type in the names in the ARRAY statement.&amp;nbsp; If you need to apply this process multiple times with many different sets of variable names, I might reconsider and recommend the macro approach.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Nov 2018 23:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/511876#M137776</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-09T23:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to rename variable names in batch, maybe using array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/513917#M138535</link>
      <description>Thank you Astounding, that's exactly what I'm looking for!</description>
      <pubDate>Fri, 16 Nov 2018 15:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-rename-variable-names-in-batch-maybe-using-array/m-p/513917#M138535</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2018-11-16T15:34:37Z</dc:date>
    </item>
  </channel>
</rss>

