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 (March 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 15 Mar 2001 15:03:09 -0500
Reply-To:     Jim Brittain <zqr0@CDC.GOV>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Brittain <zqr0@CDC.GOV>
Subject:      Re: Adding Prefix to Variable Names

I see there are already a few approaches to doing this but how about another since I already started writing it.

1. Proc Contents with the Out= option to get a list of all of the variable names. 2. Write a temp file with a long Rename statement. 3. Set the TEMP dataset into itself and use %INCLUDE to add in you dynamic code that was just created.

%MACRO prefix_vars (prefix) ;

proc contents data=mydata out =varlist noprint ; run ;

filename rncode temp ;

data _null_ ; file rncode ; set varlist (keep=name) end=last ; if (_N_=1) then put " rename " name "= &prefix" name ; else put " " name "= &prefix" name ; if (last) then put " " name "= &prefix" name / " ;" ; run ;

data mydata ; set mydata ; %INCLUDE rncode /source2 ; run ;

%MEND prefix_vars ;

%PREFIX_VARS (CA_) ;

proc contents data=mydata ; run ;

The data _null_ Rename step could be replaced by a series of Rename statements instead to shorten your Macro. ie.

data _null_ ; file rncode ; set varlist (keep=name) ; if (_N_=1) then put " rename " name "= &prefix" name ";" ; run ;

Happy SASing, Jim

-----Original Message----- From: Craig Gale [mailto:ouisc@YAHOO.COM] Sent: Thursday, March 15, 2001 9:56 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Adding Prefix to Variable Names

Good morning,

I am working on a data set containing hundreds of observations as well as hundreds of variables. My ultimate goal is to add three characters, "CA_" as a prefix to all my variable names.

My plan has been to use PROC TRANSPOSE to create the variable _NAME_, which I'm able to manipulate, and then PROC TRANSPOSE everything back producing the new manipulated variable names. But I've run into a simple problem here. I'd have to VAR the entire list of variables so that character variables are also transposed.

Is there an easier way to accomplish this task other than PROC TRANSPOSE? And if not, is there an easy way to produce a list of variable names that would be easy to cut and paste into a VAR statement?

Craig Gale Biostatistician Marshfield Clinic Marshfield, Wisconsin


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