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 (July 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 25 Jul 2001 14:25:40 -0700
Reply-To:   c-Jeff.Voeller@wcom.com
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jeff Voeller <c-Jeff.Voeller@WCOM.COM>
Subject:   Re: Another Renaming variable issue
Comments:   To: Boyd Newlin <bnewlin@INSMED.COM>
In-Reply-To:   <593004F1E467D4118ADF00508BD632D336AD01@BDC_EXCH>
Content-type:   text/plain; charset=iso-8859-1

> This might be simple but I'm trying to rename variables in a dataset > dynamically. > > Conditions: > > 1. I only want to rename the variables that begin with an 'i' > or an 'e' and > rename those variables to i1, i2, i3, etc. and e1, e2, e3, > etc respectively. > 2. I will not know the number of variables in each set. > 3. I do not want to hard code the old variables names. > 4. I need it to be done dynamically.

I just tested this code, which only deals with "i" variables:

data work.test; ivar1='This is ivar1'; ivar2='This is ivar2'; run;

proc datasets library=work memtype=data nolist; contents data=test out=work.contents; run; quit;

data _null_; set work.contents(keep=name) end=eof; if _N_=1 then do; call execute('data work.renamed;'); call execute('set work.test;'); end; if upcase(name) eq: 'I' then do; icounter+1; call execute('rename '||trim(name)||'=i' ||trim(left(put(icounter,5.)))||';'); end; if eof then call execute('run;'); run;


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