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 (November 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 7 Nov 2002 01:09:28 +0800
Reply-To:     fred <xkrim3@hotmail.com>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         fred <xkrim3@HOTMAIL.COM>
Organization: xk
Subject:      * macro to rename variables *

Hi all

I've written some code to rename 250 variables in my dataset. The code works but it is extremely inefficient. Too much iteration. Would appreciate your advice. Thanks.

* to produce sample data ; %let class=alpha ; data oldset_&class ; do i=1 to 250 ; val = int(ranuni(1)*100) ; output ; end ; drop i ; run ; proc transpose data=oldset_&class out=newset_&class(drop=newname) name=newname prefix=Var ; run ;

* can the following code be made more efficient? too much iteration. can a call symput statement be used to dump the entire 'chngname' string into macro rename1 ? ; %macro rename1(chgname=chgname, class=&class); options mprint mlogic ; data newset&class ; set newset&class ; rename &chgname ; label &chgname ; run ; %mEnd rename1 ;

%macro rename2(class=alpha) ; options mprint mlogic ; proc contents data=newset_&class out=list_&class (keep=name) noprint ; run ; data name_&class ; set list_&class ; if name not in ('Var2','Var100') then chgname = trim(name)||"="||trim(name)||"_&class" ; * Var2 & Var100 excluded ; call execute ('%rename1(chgname='||chgname||",class=_&class)" ) ; * rename2 calls rename1 ; run ; %mEnd rename2 ;

%rename2(class=alpha)


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