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 17:36:05 -0400
Reply-To:     Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Quentin McMullen <QuentinMcMullen@WESTAT.COM>
Subject:      Re: Another Renaming variable issue
Comments: To: Boyd Newlin <bnewlin@INSMED.COM>
Content-Type: text/plain; charset="iso-8859-1"

Hi Boyd,

The below macro takes in a list of variable names and generates (I think) the rename statements you want.

HTH, --Q.

%macro rename (vars); /*input list of variables to be converted*/ %local i var icount ecount ;

%let icount=1; %let ecount=1;

%let i=1; %let var=%scan(&vars,&i); %do %while (&var ne %str()); /*do over list of variable names */ %let firstlet=%upcase(%sysfunc(substr(&var,1,1))); /*first letter of varname*/

%if &firstlet=I %then %do; &var=i&icount /*rename code is generated here*/ %let icount = %eval(&icount+1); %end; %else %if &firstlet=E %then %do; &var=e&ecount /*rename code is generated here*/ %let ecount = %eval(&ecount+1); %end;

%let i = %eval(&i+1); %let var=%scan(&vars,&i); %end; %mend rename;

data a; retain id add ityx ityz ityo etcci ecrti eztt 0; run;

proc sql noprint; select name into :varlist separated by " " from dictionary.columns where libname="WORK" and memname="A" ; quit;

data b; set a (rename=(%rename(&varlist))); run;

-----Original Message----- From: Boyd Newlin [mailto:bnewlin@INSMED.COM] Sent: Wednesday, July 25, 2001 4:21 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Another Renaming variable issue

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.

For example variable names:

id add ityx ityz ityo etcci ecrti eztt

Rename the above to:

id add i1 i2 i3 e1 e2 e3

I've tried many different renaming macros from different sources and tried my own but I can't seem to get it. I think I need some different eyes to look at it.

Thanks for your help.

Boyd

Boyd Newlin Senior Programmer Analyst Insmed Incorporated, Biometrics 800 East Leigh Street Suite 113 Richmond, VA 23219 804-828-6893 x157 fax 804-827-1150 bnewlin@insmed.com


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