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.
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,'+');
> /*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 ;
> 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.
> I'm trying:
> data t&i; set t&i (rename =col1 =
> /*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?