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 15:26:36 -0800
Reply-To:   pchoate <paulchoate61@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   pchoate <paulchoate61@GMAIL.COM>
Organization:   http://groups.google.com
Subject:   Re: rename a column with a macro variable
Comments:   To: sas-l@uga.edu
Content-Type:   text/plain; charset=ISO-8859-1

bigD - a couple ideas to noodle on...

This sounds like a job for NLITERAL function and the VALIDVARNAME option. Also the COMPRESS function with the F and N options.

A cheesey way around this would be to assign labels instead of names and then export and import your data using a database engine seting the DBLABEL=YES when exporting having VALIDVARNAME=v7 when importing. SAS will write the labels as names, and then when reading them will turn them into SAS v7 compliant names.

hth

Paul

On Feb 6, 3:06 pm, bigD <diaphanos...@gmail.com> wrote: > 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 coc.codes ; > > /* 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.


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