LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2001, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 13 Dec 2001 14:37:12 -0800
Reply-To:   Jason Sun <jasun@AMAZON.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jason Sun <jasun@AMAZON.COM>
Subject:   Re: Better way to rename many variables?
Comments:   To: "David L. Ward" <dward@SASHELP.COM>
In-Reply-To:   <NEBBIMOAKLOJJKLHICKCKEPDCFAA.dward@sashelp.com>
Content-Type:   text/plain; charset="iso-8859-1"

Another way is:

a. use proc contents to output all var names to a dataset

b. use a do statement and call symput to output all names into macro variables like &old_i

c. then use a do statement to rename all like: &&old_&i.._new = &&old_&i.

This way you can keep the original names and add a surffix to the end of each.

Need a little work to write a macro. I have done it before for handreds of vars and it worked fine.

Jason Sun Amazon.com

> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of > David L. Ward > Sent: Thursday, December 13, 2001 2:26 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Better way to rename many variables? > > > This is the reason for the SAS macro language. If your variables > are named > in some kind of convention is makes it easy. I.e. > > %macro rename(n); > /* GENERATE RENAME STATEMENT */ > rename > %do I = 1 %to &n; > old&I = new&i > %end; > %mend; > > data new; > set old; > %rename(100); > run; > > Or, better yet, use proc datasets so you don't have to process the whole > data set again. > > HTH > David Ward > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of > Mahboobeh Safaeian > Sent: Thursday, December 13, 2001 4:53 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Better way to rename many variables? > > Hi > > I was wondering if there is a better/more efficient way of renaming 100 or > more variable, instead of using the 'rename=...' ? > > thanks > mahboobeh >


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