<?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 Rename with array statement....need some help in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57917#M16159</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or use proc datasets which could be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data class; 
 set sashelp.class;
run;


%let libname=work;
%let dset=class;
%let varnames=age height weight;

%macro doit;
proc datasets library=&amp;amp;libname memtype=data nolist;
 modify &amp;amp;dset ;
 rename 
 %do i=1 %to %sysfunc(countw(&amp;amp;varnames));
&amp;nbsp; %scan(&amp;amp;varnames,&amp;amp;i)= key&amp;amp;i
 %end;
 ;
quit;
%mend doit;

%doit
&amp;nbsp; 


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 20 Feb 2012 03:20:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2012-02-20T03:20:24Z</dc:date>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57912#M16154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone! I'm new to the forums so I'm sorry if this is in the wrong place to post this question. Basically I'm completely stumped here. I got the follwoing code, I'm hoping to use to rename elements of an array....&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;data notarget_temp1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;set &amp;amp;dset.;&lt;/P&gt;&lt;P align="left"&gt;array arr_varlst{*} &amp;amp;varnames.;&lt;/P&gt;&lt;P align="left"&gt;%do i = 1 %to &amp;amp;nvars.;&lt;/P&gt;&lt;P align="left"&gt;rename arr_varlst{&amp;amp;i.} = key_&amp;amp;i.;&lt;/P&gt;&lt;P align="left"&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;run;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;﻿&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt;The problem appears to the rename statement, as I get the following error...&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt;﻿&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;﻿&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: -, :, =.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;﻿&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt;Really I have no idea what is going on here. Pretty sure I've used code exactly like this in the past. As an FYI the whole thing is wrapped in a bigger macro, all the macro variables in the block are resolving fine...&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;Thanks, &lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 8pt;"&gt;Joe ﻿&lt;/SPAN&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P align="left"&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; color: #000000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 21:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57912#M16154</guid>
      <dc:creator>jcauteru</dc:creator>
      <dc:date>2012-02-17T21:43:52Z</dc:date>
    </item>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57913#M16155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you need an array.&amp;nbsp; How about?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let dset=sashelp.class;&lt;/P&gt;&lt;P&gt;%let varnames=age height weight;&lt;/P&gt;&lt;P&gt;%let nvars=3;&lt;/P&gt;&lt;P&gt;%macro doit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data notarget_temp1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;dset.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to &amp;amp;nvars.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename %scan(&amp;amp;varnames.,&amp;amp;i.) = key_&amp;amp;i.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%doit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 22:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57913#M16155</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-17T22:01:29Z</dc:date>
    </item>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57914#M16156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Macro processing is completed before the DATA step executes.&amp;nbsp; This means that array&amp;nbsp; will not yet exist when the %DO executes.&amp;nbsp; You need to extract the variable name without using the array.&amp;nbsp; The %SCAN macro function will do the trick.&amp;nbsp; Untested code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data notarget_temp1;&lt;/P&gt;&lt;P&gt;set &amp;amp;dset.;&lt;/P&gt;&lt;P&gt;%do i = 1 %to &amp;amp;nvars.;&lt;/P&gt;&lt;P&gt;rename %scan(&amp;amp;varnames,&amp;amp;i,%str( )) = key_&amp;amp;i.;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 22:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57914#M16156</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-02-17T22:06:47Z</dc:date>
    </item>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57915#M16157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks to both of you. %scan works. Art, thanks for the additional explination, very helpful. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 22:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57915#M16157</guid>
      <dc:creator>jcauteru</dc:creator>
      <dc:date>2012-02-17T22:13:27Z</dc:date>
    </item>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57916#M16158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%let dset=sashelp.class;&lt;/P&gt;&lt;P&gt;%let varnames=age height weight;&lt;/P&gt;&lt;P&gt;%let nvars=3;&lt;/P&gt;&lt;P&gt;%macro doit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data notarget_temp1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;dset.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename %do i = 1 %to &amp;amp;nvars.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %scan(&amp;amp;varnames.,&amp;amp;i.) = key_&amp;amp;i.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%doit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Feb 2012 22:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57916#M16158</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-02-17T22:46:44Z</dc:date>
    </item>
    <item>
      <title>Rename with array statement....need some help</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57917#M16159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or use proc datasets which could be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data class; 
 set sashelp.class;
run;


%let libname=work;
%let dset=class;
%let varnames=age height weight;

%macro doit;
proc datasets library=&amp;amp;libname memtype=data nolist;
 modify &amp;amp;dset ;
 rename 
 %do i=1 %to %sysfunc(countw(&amp;amp;varnames));
&amp;nbsp; %scan(&amp;amp;varnames,&amp;amp;i)= key&amp;amp;i
 %end;
 ;
quit;
%mend doit;

%doit
&amp;nbsp; 


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Feb 2012 03:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rename-with-array-statement-need-some-help/m-p/57917#M16159</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-02-20T03:20:24Z</dc:date>
    </item>
  </channel>
</rss>

