<?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 variables in an array in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807442#M33625</link>
    <description>&lt;P&gt;It doesn't sound like you want to RENAME anything.&amp;nbsp; Instead it sounds like you want to make NEW variables.&lt;/P&gt;
&lt;P&gt;So use TWO arrays. One for the original variables and one for the new variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array original mpg_city mpg_highway;
  array new kpg_cit kpg_highway;
  do index=1 to dim(original);
    new[index] = 1.6 * original[index];
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Apr 2022 18:12:43 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-12T18:12:43Z</dc:date>
    <item>
      <title>Rename variables in an array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807439#M33624</link>
      <description>&lt;P&gt;I'm trying to learn arrays in SAS. In the example below I am using the sashelp.cars data set and converting mpg_city and mpg_highway into km.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. How would I rename the variables to kmpg_city and kmpg_highway?&lt;/P&gt;
&lt;P&gt;2. And, how would I create new variables called kmpg_city and kmpg_highway, so that I can keep the mpg_city and mpg_highway variables in the dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without using an array I would just do this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;kmpg_city = mpg_city*1.6&lt;/P&gt;
&lt;P&gt;kmpg_highway = kmpg_highway*1.6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.cars;

/* Array statement (i.e., ARRAY) */
/* Array name (e.g., array_name) */
/* Number of elements (i.e., the number of vars. (*) tells SAS to figure it out) */
/* Elements (i.e., the vars) */
   ARRAY array_name(*) mpg_city mpg_highway ;
    
/* DO loop specifies the index variable and tells SAS how many iterations thru the loop. */
/* DIM tells SAS to figure out the number of iterations based on the number of elements.  */ 
   DO index_var = 1 to DIM (array_name);
   
/* The syntax you want. */
/* Write the syntax for 1 variable, then substitute the array name followed by the index var name in squiggly brackets. */
   array_name {index_var} = array_name {index_var}*1.6;
   END;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 18:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807439#M33624</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-04-12T18:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in an array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807442#M33625</link>
      <description>&lt;P&gt;It doesn't sound like you want to RENAME anything.&amp;nbsp; Instead it sounds like you want to make NEW variables.&lt;/P&gt;
&lt;P&gt;So use TWO arrays. One for the original variables and one for the new variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array original mpg_city mpg_highway;
  array new kpg_cit kpg_highway;
  do index=1 to dim(original);
    new[index] = 1.6 * original[index];
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Apr 2022 18:12:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807442#M33625</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-12T18:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in an array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807458#M33626</link>
      <description>&lt;P&gt;Thank you. I will check this out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To clarify, I'd like to learn how to rename variables processed in an array AND create new variables in an array.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 18:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807458#M33626</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-04-12T18:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Rename variables in an array</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807459#M33627</link>
      <description>&lt;P&gt;Arrays cannot be used to rename variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has already shown how to create new variables.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 18:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rename-variables-in-an-array/m-p/807459#M33627</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-12T18:48:48Z</dc:date>
    </item>
  </channel>
</rss>

