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 (October 2005, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Mon, 31 Oct 2005 15:53:20 -0500
Reply-To:   "Fehd, Ronald J" <rjf2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J" <rjf2@CDC.GOV>
Subject:   Re: SAS programming question/problem
Content-Type:   text/plain; charset="US-ASCII"

> From: Nick .

> I have a SAS (V8.2) data set with, say, 5 fields (in my data > set it has like 500 fields) called VAR1, VAR2,..., VAR5. > I have an Excel data set that looks like this: > A B > VAR1 Age > VAR2 Income > VAR3 Gender > VAR4 Num_Accts > VAR5 Zip_Code > > I need to go to my SAS data set above and replace the field > names VAR1,...,VAR5 with > Age, Income, Gender, Num_Accts, Zip_Code respectively. (A and > B are the column headings in Excel sheet, not of importance, > I guess.) Thanks.

as always: Why do you want to do this?

and then next Q: do you want to rename or add labels?

*rename; Data New; set Old(rename = (Var1 = Age ... ) );

PROC SQL; select trim(OldName) !! ' = ' !! trim(NewName) into :List separated by ' ' from ListOfNames ;quit;

Data New; set Old(rename = (&List.));

... hm 500 variables? probably a lot of rows, too, eh?! so use proc DataSets to do the rename: just change the data structure, not read the entire data set.

you can use a similar list processing trick to add labels: label Var1 = 'Age' ...;

watch those single and double quotes when you build :List

PROC SQL; select trim(OldName) !! " = '" !! trim(NewName) !! "'" ... etc.

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov


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