LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 17 Apr 2007 14:00:59 -0500
Reply-To:   "Huang, JS" <Huang.JS@PRINCIPAL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Huang, JS" <Huang.JS@PRINCIPAL.COM>
Subject:   Re: Can I use array to rename variables?
Comments:   To: Sophia Tong <sophiDT@HOTMAIL.COM>
In-Reply-To:   A<200704171807.l3HAlVnk029298@mailgw.cc.uga.edu>
Content-Type:   text/plain; charset="us-ascii"

A little macro might help:

data PEGT3; input var1 var2 var3; datalines; 1 2 3 4 5 6 7 8 9 ;

proc print data=PEGT3; run;

%macro Rename(n); %global rename; %let rename=; %do i=1 %to &n; %let rename=&rename var&i=var&i.__3; %end; %mend;

%Rename(3);

DATA PEGT3A; SET PEGT3; RENAME &rename; RUN;

proc print data=PEGT3A; run;

***** Output ***** The SAS System 11:12 Tuesday, April 17, 2007 30

Obs var1 var2 var3

1 1 2 3 2 4 5 6 3 7 8 9

The SAS System 11:12 Tuesday, April 17, 2007 31

Obs var1__3 var2__3 var3__3

1 1 2 3 2 4 5 6 3 7 8 9

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Sophia Tong Sent: Tuesday, April 17, 2007 1:08 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Can I use array to rename variables?

I have a set of variables need to be renamed, I tried the following code and get error message, not sure if it's not feasible or just simply a syntax error.

Please offer your expertise,Many thanks in advance.

%LET NAME=var1 var2 ....varn; DATA PEGT3A; SET PEGT3; ARRAY VARN [*] &NAME; DO I=1 TO DIM(VARN); RENAME VARN[I]=VARN[I] || '__'||3; END; RUN;

LOG:

RENAME VARN[I]=VARN[I] || '__'||3; - 22 76 ERROR 22-322: Syntax error, expecting one of the following: -, :, =.

ERROR 76-322: Syntax error, statement will be ignored.

-----Message Disclaimer-----

This e-mail message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not the intended recipient, any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by reply email to Connect@principal.com and delete or destroy all copies of the original message and attachments thereto. Email sent to or from the Principal Financial Group or any of its member companies may be retained as required by law or regulation.

Nothing in this message is intended to constitute an Electronic signature for purposes of the Uniform Electronic Transactions Act (UETA) or the Electronic Signatures in Global and National Commerce Act ("E-Sign") unless a specific statement to the contrary is included in this message.

While this communication may be used to promote or market a transaction or an idea that is discussed in the publication, it is intended to provide general information about the subject matter covered and is provided with the understanding that The Principal is not rendering legal, accounting, or tax advice. It is not a marketed opinion and may not be used to avoid penalties under the Internal Revenue Code. You should consult with appropriate counsel or other advisors on all matters pertaining to legal, tax, or accounting obligations and requirements.


Back to: Top of message | Previous page | Main SAS-L page