<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44463#M9100</link>
    <description>1. if there are different data types in these variables array will not work. &lt;BR /&gt;
2. the do loop in the data step should not use %, i.e. this is not a macro level loop.&lt;BR /&gt;
&lt;BR /&gt;
what messages do you get from the log?</description>
    <pubDate>Thu, 21 Jan 2010 19:50:17 GMT</pubDate>
    <dc:creator>abdullala</dc:creator>
    <dc:date>2010-01-21T19:50:17Z</dc:date>
    <item>
      <title>Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44461#M9098</link>
      <description>Whats wrong with the code below to rename all the varibles to F1 to F16?&lt;BR /&gt;
&lt;BR /&gt;
%maCRO rename;&lt;BR /&gt;
data national_temp_v2;  &lt;BR /&gt;
set national_temp_v1;&lt;BR /&gt;
array fields(*)  ndc_code--Dr__DEA;&lt;BR /&gt;
   %do i=1 %to 16;&lt;BR /&gt;
   rename fields(i)=F&amp;amp;i.;&lt;BR /&gt;
   %end;&lt;BR /&gt;
run;&lt;BR /&gt;
%mend rename;&lt;BR /&gt;
%rename;</description>
      <pubDate>Thu, 21 Jan 2010 19:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44461#M9098</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-01-21T19:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44462#M9099</link>
      <description>You can't use arrays and rename in that way.  You might do it this way. &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
*Create Test data;&lt;BR /&gt;
data test;&lt;BR /&gt;
   if 0 then set sashelp.air;&lt;BR /&gt;
   length ndc_code $1;&lt;BR /&gt;
   if 0 then set sashelp.class sashelp.shoes;&lt;BR /&gt;
   length Dr__DEA 8;&lt;BR /&gt;
   call missing(of _all_);&lt;BR /&gt;
   stop;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc contents order=varnum;&lt;BR /&gt;
   run;&lt;BR /&gt;
 &lt;BR /&gt;
*Rename a range of variables to an enumerated list;&lt;BR /&gt;
proc transpose data=test(obs=0) out=vars;&lt;BR /&gt;
   var ndc_code--Dr__DEA;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data vars;&lt;BR /&gt;
   set vars;&lt;BR /&gt;
   length new $32;&lt;BR /&gt;
   new = cats('F',_n_);&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
   select catx('=',_name_,new) into :rename separated by ' '&lt;BR /&gt;
      from vars;&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc datasets;&lt;BR /&gt;
   modify test;&lt;BR /&gt;
   rename &amp;amp;rename;&lt;BR /&gt;
   run;&lt;BR /&gt;
   contents data=test order=varnum;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 21 Jan 2010 19:48:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44462#M9099</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-01-21T19:48:28Z</dc:date>
    </item>
    <item>
      <title>Re: Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44463#M9100</link>
      <description>1. if there are different data types in these variables array will not work. &lt;BR /&gt;
2. the do loop in the data step should not use %, i.e. this is not a macro level loop.&lt;BR /&gt;
&lt;BR /&gt;
what messages do you get from the log?</description>
      <pubDate>Thu, 21 Jan 2010 19:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44463#M9100</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2010-01-21T19:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44464#M9101</link>
      <description>or you may simply create new variables F1 -- F16 in the loop, as&lt;BR /&gt;
 array f (*) f1 - f16;&lt;BR /&gt;
&lt;BR /&gt;
...&lt;BR /&gt;
&lt;BR /&gt;
do i=1 to dim(f);&lt;BR /&gt;
 f(i)=field(i);&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
then delete the original fields.</description>
      <pubDate>Thu, 21 Jan 2010 19:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44464#M9101</guid>
      <dc:creator>abdullala</dc:creator>
      <dc:date>2010-01-21T19:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44465#M9102</link>
      <description>You are attempting to mix MACRO language with DATA step language - the two are not compatible.&lt;BR /&gt;
&lt;BR /&gt;
Also you cannot use an ARRAY to reference variables for a rename process because RENAME occurs at the step-level and the ARRAY reference is not.&lt;BR /&gt;
&lt;BR /&gt;
If you have no need to pass your data, suggest using PROC DATASETS and MODIFY.&lt;BR /&gt;
&lt;BR /&gt;
You will find useful technical reference material at the SAS support &lt;A href="http://suppor.sas.com/" target="_blank"&gt;http://suppor.sas.com/&lt;/A&gt;  website using the Google advanced argument listed below:&lt;BR /&gt;
&lt;BR /&gt;
rename all variables site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 21 Jan 2010 20:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44465#M9102</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-01-21T20:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Rename</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44466#M9103</link>
      <description>Data _null_,&lt;BR /&gt;
  Thanks for the help.&lt;BR /&gt;
Its neat and nice.&lt;BR /&gt;
SASPhile.</description>
      <pubDate>Thu, 21 Jan 2010 20:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rename/m-p/44466#M9103</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2010-01-21T20:40:31Z</dc:date>
    </item>
  </channel>
</rss>

