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 (February 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 6 Feb 2008 23:48:20 +0000
Reply-To:   toby dunn <tobydunn@HOTMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   toby dunn <tobydunn@HOTMAIL.COM>
Subject:   Re: rename a column with a macro variable
Comments:   To: bigD <>
In-Reply-To:   <>
Content-Type:   text/plain; charset="iso-8859-1"

BigD ,

Yes it should and if you post an example starting data set andwhat you expect the ending data set to look like I bet we can get you from point A to point B with a cleaner solution.

Toby Dunn

"Don't bail. The best gold is at the bottom of barrels of crap." Randy Pausch

"Be prepared. Luck is where preparation meets opportunity." Randy Pausch

> Date: Wed, 6 Feb 2008 15:06:49 -0800 > From: diaphanosoma@GMAIL.COM > Subject: rename a column with a macro variable > To: SAS-L@LISTSERV.UGA.EDU > > I'm trying to rename a column in a data set with a macro variable > name. Should be easy, but I can't do it. > Here is the pertinent code: > > /*Load unique causes of death into death_names*/ > > proc sql; > select distinct quote(trim(death_cause)) > into :death_names separated by '+' > from ; > > /* loop through for each distinct death name */ > > %do i= 1 %to &sqlobs.; > > DATA NEW&i; SET coc.death; > where coc=&geog and icd10_description= %scan(&death_names.,&i,'+'); > RUN; > > /*works nicely */ > > lots more code...... > > /*I want to make the last data set anemable to merging all the work > data sets together > so I transpose the data and sort */ > > proc transpose data=new4&i out =t&i ; > run; > > proc sort data=t&i ; by _name_; > > /* Next I want to to rename the automatic variable "col1", which > contains the data, to > the variable name stored in the macro. I can't seem to do it. > The names of the variable are something like "cancer of bladder & > urinary tract" or "cancer of colon", these can't be variable names > becuase they are more than one word long. Also note the "&" that > needs to be dealt with. I'm trying to compress the blanks. Ideally I > would like to subsitute the blanks for underscores e.g. > cancer_of_bladder. > > I'm trying: > > data t&i; set t&i (rename =col1 = > %cmpres(%scan(&death_names.,&i,'+'))); > > > /*lots of errors but after playing with it a bit (qstrn, qcmpres, > etc)I can get a variable name of " " " (a quotation mark) > > > How can I get the rename to work here? > > > Thanks, > > B.

_________________________________________________________________ Need to know the score, the latest news, or you need your HotmailŪ-get your "fix".

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