<?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: Array Error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828185#M327147</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don't really need to rename the variables. My main purpose is to change numeric to chatater.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS doesn't allow conversion within the same variable name so you need new variable names.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2022 22:46:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-08-10T22:46:04Z</dc:date>
    <item>
      <title>Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828168#M327138</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I would like to change some variables from numeric to character.&amp;nbsp; I use array function, but I found some error messages in the log window.&amp;nbsp; Please help.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cost_demagrapy_2;
	set cost_demagrapy;
	array var {*} Sex Age Insurance race;                                                                                                    
     do i=1 to dim(var);                                                                                                                
      	rename newvar=var(i);
		var_=put(newvar(i),10.);
		drop var(i); 
     output;                                                                                                                             
     end;   
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2022 20:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828168#M327138</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-08-10T20:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828169#M327139</link>
      <description>545  data cost_demagrapy_2;&lt;BR /&gt;546      set cost_demagrapy;&lt;BR /&gt;547      array var {*} Sex Age Insurance race;&lt;BR /&gt;548       do i=1 to dim(var);&lt;BR /&gt;549          rename newvar=var(i);&lt;BR /&gt;                              -&lt;BR /&gt;                              22&lt;BR /&gt;                              76&lt;BR /&gt;550          var_=put(newvar(i),10.);&lt;BR /&gt;                      ------&lt;BR /&gt;                      68&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;.&lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;&lt;BR /&gt;ERROR 68-185: The function NEWVAR is unknown, or cannot be accessed.&lt;BR /&gt;&lt;BR /&gt;551          drop var(i);&lt;BR /&gt;                     -&lt;BR /&gt;                     22&lt;BR /&gt;                     76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;, _ALL_, _CHARACTER_,&lt;BR /&gt;              _CHAR_, _NUMERIC_.&lt;BR /&gt;&lt;BR /&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;&lt;BR /&gt;552       output;&lt;BR /&gt;553       end;&lt;BR /&gt;554  run;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 10 Aug 2022 20:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828169#M327139</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-08-10T20:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828170#M327140</link>
      <description>&lt;P&gt;I don't think you can use rename in that fashion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also seem to be referencing an array newvar(i) but I don't see any such array declared.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 21:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828170#M327140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-10T21:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828174#M327144</link>
      <description>&lt;P&gt;So your code has a major logic error that the SAS compiler cannot detect.&lt;/P&gt;
&lt;P&gt;But it also have two syntax errors that it can detect.&lt;/P&gt;
&lt;P&gt;If you want to use parentheses in a variable name you need set the option VALIDVARNAME to ANY and then use a name literal in your code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;rename newvar='var(i)'n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to reference an element in an array you need to first define the array.&amp;nbsp; You never defined any NEWVAR as an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps you meant to do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cost_demagrapy_2;
  set cost_demagrapy;
  array OLD Sex Age Insurance race;
  array NEW $10 _Sex _Age _Insurance _race;
  do index=1 to dim(old);
    new[index]=put(old[index],10.);
  end;
  rename _Sex=Sex _Age=Age _Insurance=Insurance _race=race;
  drop Sex Age Insurance race index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 21:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828174#M327144</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-10T21:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828178#M327145</link>
      <description>&lt;P&gt;Are you really trying to rename variables to the value of a different variable????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not in rename statement. Rename is not executable. The Rename statement (or data set option) requires you to specify the name as text. You cannot use the value of a variable on the rename statement.&lt;/P&gt;
&lt;P&gt;The data step basically doesn't allow you to use functions to build variable names at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your partial statement "some variables from numeric to character. I use array function" just will not work. Variables in an array must be all of the same type, either all numeric or all character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get the name of a variable referenced in an array with the VNAME such as where Var[i] is a legal array reference:&lt;/P&gt;
&lt;PRE&gt;Thevariablenameis = vname(var[i]);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As we very frequently ask: provide an example of the data in data step form and the desired result.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 21:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828178#M327145</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-08-10T21:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828184#M327146</link>
      <description>I don't really need to rename the variables.  My main purpose is to change numeric to chatater.</description>
      <pubDate>Wed, 10 Aug 2022 22:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828184#M327146</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-08-10T22:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828185#M327147</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don't really need to rename the variables. My main purpose is to change numeric to chatater.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS doesn't allow conversion within the same variable name so you need new variable names.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2022 22:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-Error/m-p/828185#M327147</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-08-10T22:46:04Z</dc:date>
    </item>
  </channel>
</rss>

