Date: Wed, 25 Feb 1998 21:16:00 -0500
Reply-To: Dave_Mabey_at_RDA8POSTOFFICE1@RDCCMAIL.READERSDIGEST.COM
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Dave_Mabey_at_RDA8POSTOFFICE1@RDCCMAIL.READERSDIGEST.COM
Subject: Re: RENAMING A LARGE # OF VARIABLES
Content-type: text/plain; charset=US-ASCII
New Text Item: RENAMING A LARGE # OF VARIABLES
Been there, done that (often). This should get you started.
Just replace the libname and memname in the SQL, assuming
you are not work with sequential datasets (tapes). The macro
var can be up to 32K characters ... You won't have problems with
rename for just 200 variables, but if you start to modify the
variable label on a few thousand variables you will have to break
up the string. In the example, I use the macro variable in the
SET statement of a datastep. You might consider using it in
a PROC DATASETS ...; MODIFY ....; RENAME &MACVAR;
165 data a;
166 array vars vara varb longname;
167 put _all_;
168
169
_I_=. VARA=. VARB=. LONGNAME=. _ERROR_=0 _N_=1
NOTE: The data set WORK.A has 1 observations and 3 variables.
NOTE: The DATA statement used 0.33 seconds.
170 proc sql noprint;
171 select compress(name||'='
172 ||substr(name,1,6)||'95')
173 into :macvar separated by ' '
174 from sashelp.vcolumn
175 where libname="WORK"
176 & memname='A';
177
178 %put &macvar;
VARA=VARA95 VARB=VARB95 LONGNAME=LONGNA95
179
NOTE: The PROCEDURE SQL used 0.08 seconds.
180 data b;
181 set a (rename=(&macvar));
182 put _all_;
183 run;
VARA95=. VARB95=. LONGNA95=. _ERROR_=0 _N_=1
NOTE: The data set WORK.B has 1 observations and 3 variables.
NOTE: The DATA statement used 0.28 seconds.
______________________________ Reply Separator ____________________________
_____
Subject: RENAMING A LARGE # OF VARIABLES
Author: agmariam@UMICH.EDU@INTERNET at RDNOTES
Date: 2/25/98 5:01 PM
(Embedded image moved to file: PIC001.PCX)
Hi! all,
I have two datasets with the same set of variables and same variable names.
The datasets are for 1994 and 1995. I would like to rename the variables in
one of the datasets but the number of variables is about 200.
Is there a more efficient way to do it than to rename all these variables
manually?
If I want to add 95 to all the variable names in the 1995
dataset, then how do I do that?
Thanks for your help.
Acham.
*************************************************************************
*****
* GOD IS NOT IN A HURRY BUT HE IS ALWAYS ON TIME *
*------------------------------------------------------------------------
----*
* Achamyeleh Gebremariam * * e-mail agmariam@umich.edu *
*************************************************************************
*****
SMTPOriginator: owner-sas-l@UGA.CC.UGA.EDU