Date: Thu, 21 Feb 2002 17:06:20 -0500
Reply-To: Edward Heaton <HEATONE@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Edward Heaton <HEATONE@WESTAT.COM>
Subject: Re: renaming many variables
Content-Type: text/plain; charset="iso-8859-1"
Scott,
First, import your lists of variable names from Excel to SAS. Suppose
the SAS data set is called MAP and the columns are called SLOT and VARNAME.
Furthermore, suppose both variables are character. Then you would want to
code something like the following.
Proc sql noPrint ;
Select
"var" || trim( slot ) || "=" || trim( varName )
into :renames separated by " "
from map
;
Quit ;
Now, suppose your imported csv file is called myData. Then you can use PROC
DATASETS as follows.
Proc dataSets library=work ;
Modify myData ;
Rename &renames ;
Run ;
Quit ;
DISCLAIMER: I have NOT tested this code and, given my recent propencity for
responding with error-laden code, I STRONGLY SUGGEST the user test this code
on test data before applying it to a real-life situation!! :-o
Ed
Edward Heaton, Senior Systems Analyst,
Westat (An Employee-Owned Research Corporation),
1550 Research Boulevard, Room 2018, Rockville, MD 20850-3195
Voice: (301) 610-4818 Fax: (301) 294-3992
mailto:EdwardHeaton@westat.com http://www.westat.com
-----Original Message-----
From: Miller, Scott [mailto:smiller@WVMI.ORG]
Sent: Thursday, February 21, 2002 4:27 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: renaming many variables
ok...i know this might have been hashed around already, but i couldnt find
exactly what i was looking for in the list searches. so here we go again.
we have software that saves data in a csv format from ms access into 2 text
files. each of these files uses a slot map variable naming scheme, so that
the first row of the csv file is 0,1,2,3....235. ok...now, since the
software has different instruments, the variable label for these slots
changes depending on what instrument was completed. so slot 25 might be
systolic pressure for one instrument, and diastolic pressure on another
instrument. i have written, to take care of this in the present time frame,
code that renames these variables based on what instrument the data was
related to. also, these slot maps to variable names change every quarter,
where new variables have been added or some removed. when i import this csv
data, sas gives the variables names of var1-var236. then i do a rename
statement like var1=id var2=name etc. all the way to var236. i have in
excel the map that says slot 0 is id and slot 1 is name, so i construct the
rename statement in excel, then copy it and paste it into the sas code. so
everything works ok now. now i cant help but wonder if there is a way to
take a variable list, maybe in a macro, and have it be renamed to a second
variable list? any help or insight you can give me would make several
peoples lives more bearable. TIA
Scott D. Miller, MA
Evaluation and Informatics Analyst
West Virginia Medical Institute
(304) 346-9864 ext 2240
Every good scientist should be one part P.T. Barnum and one part B.F.
Skinner.
The goal of science is to build better mousetraps. The goal of nature is to
build better mice.
Sumus quid sumus
|