BookmarkSubscribeRSS Feed
NKormanik
Barite | Level 11

 

Because of variable length limits, etc., I simply renamed all variables:

 

i_01

i_02

i_03

 

But each variable really should be associated with a longer, more descriptive name:

 

Abc.......

Def.......

Ghi.......

 

I've imported the dataset using the simple variable names.  But I'd like to somehow 'import' the longer respective names as 'labels'.  Can that be done?  If so, how?

 

Thanks,

Nicholas Kormanik

 

3 REPLIES 3
Patrick
Opal | Level 21

I've imported the dataset using the simple variable names.

HOW did you import the data. In what format is the source? Please provide a bit more detail.

 

sbxkoenk
SAS Super FREQ

If you can make a dataset that has the short names in one column and the long names in a second column, then you can proceed as in the program below ... (the long names will serve as label).

data have;
 set sashelp.class;
run;

data short_and_long;
LENGTH varname $ 6 varlabel $ 20; 
varname='Name';   varlabel='xxxxx Name xxxxx';   output;
varname='Sex';    varlabel='xxxxx Sex xxxxx';    output;
varname='Age';    varlabel='xxxxx Age xxxxx';    output;
varname='Height'; varlabel='xxxxx Height xxxxx'; output;
varname='Weight'; varlabel='xxxxx Weight xxxxx'; output;
run;

filename shorlong temp;

data _NULL_;
 set short_and_long end=last;
 file shorlong; 
 if _N_=1 then do;
PUT 'proc datasets library=work NoList NoDetails memtype=data;';
PUT ' modify have;';
 end;
PUT "label " varname "='" varlabel +(-1) "';";
 if last then do;
PUT 'run; QUIT;';
 end;
run;

%INCLUDE shorlong / source2;
/* end of program */

Koen

A_Kh
Lapis Lazuli | Level 10

Similar approach to the above, but using sql and macro:

/*Creating a macro variable "LABELS" that contains variable names and attributed labels*/
proc sql noprint;
	create table have as
		select distinct mnemonic, text 
			from sashelp.webmsg where length(text) eq 55;
	select catx('=', strip(mnemonic), quote(compress(text, '', 'ka'))) into:labels separated by ' ' from have; 
quit;

proc transpose data=have out=have_wide;
	var text;
	id mnemonic;
run; 

/*Applying labels to all variables using macro variable "LABELS"*/
data want;
	set have_wide;
	label &labels;
run; 

proc print data=want label; 
	label; 
run; 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2225 views
  • 4 likes
  • 4 in conversation