- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
I have a dataset with 250 columns and would like to convert all the sas labels into variable names. How to do it?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Are they all applicable as SAS variable names?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes, they are all sas variable names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@rajredy7172012 wrote:
I have a dataset with 250 columns and would like to convert all the sas labels into variable names. How to do it?
Why would you want to do that?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Generate an series of OLD=NEW pairs and use them in a RENAME statement or RENAME= dataset option. Note that labels can have up to 255 bytes, but names can only have 32. If the labels do not follow normal SAS variable naming rules then you will need to use VALIDVARNAME=ANY system option. You cannot use RENAME to change the case of a name. If you need to do that you will need to do a two step approach where you first change it something else and back to the name with different case for some of the letters. Also make sure that all of the labels are unique. You cannot have two variables with the same name.
Say your datasets is named MYDATA and it is pointed at by the libref MYLIB.
proc sql noprint;
select catx('=',nliteral(name),nliteral(substr(label,1,32)))
into :renames separated by ' '
from dictionary.columns
where libname='MYLIB'
and memname='MYDATA'
and upcase(name) ne upcase(substr(coalesce(label,name),1,32))
;
quit;
%if (&sqlobs > 0) %then %do;
proc datasets nolist lib=MYLIB;
modify mydata;
rename &renames;
run;
quit;
%end;