<?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 Assay Error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848776#M335559</link>
    <description>&lt;P&gt;The RENAME statement needs the actual names of variables.&amp;nbsp; Not an expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use your DO loop to copy the VALUES from one array to the other.&amp;nbsp; You could then drop the old variables and keep the new ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the old variables are numeric your array statements could work like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array OldName Room_ED Room_ICU ;
  array NewName Room_ED_ Room_ICU_ ;
  do i = 1 to dim(OldName);
    NewName[i]= OldName[i];
  end;
  drop i Room_ED Room_ICU ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the variables are character then you need to add a length to the ARRAY statement.&amp;nbsp; So if you want the two new variables to be character strings of length 10 the array statement would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array NewName $10 Room_ED_ Room_ICU_ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have the list of variable names as data then you could use that to GENERATE a rename statement.&lt;/P&gt;
&lt;P&gt;For example by writing it to a file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;
  input name :$32. ;
cards;
Room_ED 
Room_ICU
;

filename code temp;
data _null_;
  set names end=eof;
  file code;
  if _n_=1 then put 'rename ' @;
  put name '=' name +(-1) '_' @;
  if eof then put ';' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then tell SAS to use that file as code using the %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;Either in a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or by modifying the original dataset using PROC DATASETS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets nolist lib=work;
  modify have;
%include code / source2;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Dec 2022 19:00:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-12-09T19:00:11Z</dc:date>
    <item>
      <title>Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848769#M335556</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to rename several variables in the sample dataset.&amp;nbsp; An error message was shown in the log window.&amp;nbsp; Please let me know how to resolve them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;

	array OldName (i) Room_ED Room_ICU ;                                    
       array NewName (i) Room_ED_ Room_ICU_ ;                                      
	   do i = 1 to dim(OldName);                                      
	     rename NewName(i)= OldName(i);                                  
	   end;                                                                                              
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;53 do i = 1 to dim(OldName);&lt;BR /&gt;54 rename NewName(i)= OldName(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: -, :, =.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;55 end;&lt;BR /&gt;56 run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 18:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848769#M335556</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-12-09T18:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848774#M335558</link>
      <description>&lt;P&gt;Please show us the ENTIRE log for the DATA step that has an error. Do NOT choose parts of the log to show us and choose other parts of the log to not show us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please use the &amp;lt;/&amp;gt; icon to show us the log so we can view it with proper spacing.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1663012019648.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75161i0E71B1489A6C9839/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1663012019648.png" alt="PaigeMiller_0-1663012019648.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of this has been requested of you&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Why-the-command-statement-didn-t-work/m-p/846724#M334711" target="_self"&gt;before&lt;/A&gt;. We are trying to help you, but you have to help us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 18:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848774#M335558</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-09T18:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848776#M335559</link>
      <description>&lt;P&gt;The RENAME statement needs the actual names of variables.&amp;nbsp; Not an expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use your DO loop to copy the VALUES from one array to the other.&amp;nbsp; You could then drop the old variables and keep the new ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the old variables are numeric your array statements could work like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array OldName Room_ED Room_ICU ;
  array NewName Room_ED_ Room_ICU_ ;
  do i = 1 to dim(OldName);
    NewName[i]= OldName[i];
  end;
  drop i Room_ED Room_ICU ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the variables are character then you need to add a length to the ARRAY statement.&amp;nbsp; So if you want the two new variables to be character strings of length 10 the array statement would be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array NewName $10 Room_ED_ Room_ICU_ ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have the list of variable names as data then you could use that to GENERATE a rename statement.&lt;/P&gt;
&lt;P&gt;For example by writing it to a file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;
  input name :$32. ;
cards;
Room_ED 
Room_ICU
;

filename code temp;
data _null_;
  set names end=eof;
  file code;
  if _n_=1 then put 'rename ' @;
  put name '=' name +(-1) '_' @;
  if eof then put ';' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then tell SAS to use that file as code using the %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;Either in a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or by modifying the original dataset using PROC DATASETS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets nolist lib=work;
  modify have;
%include code / source2;
  run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848776#M335559</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-09T19:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848780#M335563</link>
      <description>&lt;PRE&gt;53          do i = 1 to dim(OldName);
54            rename NewName(i)= OldName(i);
                            -
                            22
                            76
ERROR 22-322: Syntax error, expecting one of the following: -, :, =.

ERROR 76-322: Syntax error, statement will be ignored.

55          end;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Dec 2022 18:48:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848780#M335563</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2022-12-09T18:48:26Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848788#M335567</link>
      <description>&lt;P&gt;Hello, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt; I see you already have an answer to your question, but in the future, we need the ENTIRE log for the DATA step, not the couple of lines that you choose to show us.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848788#M335567</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-09T19:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rename Assay Error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848793#M335569</link>
      <description>&lt;P&gt;&lt;A href="https://www.oxfordlearnersdictionaries.com/definition/english/entire?q=Entire" target="_blank" rel="noopener"&gt;entire&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2022 19:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename-Assay-Error/m-p/848793#M335569</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-12-09T19:52:41Z</dc:date>
    </item>
  </channel>
</rss>

