I've noticed that :
1/ Add labels - The label statement creates a WARNING when specifying a label for a variable which is only available in the output dataset e.g. _name_, _label_, col1 and so on, but still add it. The same thing can be observed with the attrib statement.
2/ Remove labels - When it comes to removing labels, it removes them but creates a warning when it comes to the automatic _name_ and _label_ variable labels. It is the same with the attrib statement using attrib _all_ label=' ' is used.
Do you have any thought on that or any literature which would cover this topic?
Here is some code to play around the different scenaries.
data class;
length student $4;
student='John'; topic1=89; topic2=12; output;
student='Mary'; topic1=53; topic2=44; output;
run;
proc print data=class noobs;
run;
proc transpose data = class
out = class_t;
by student;
var topic1 topic2;
*label student = 'Student Name'
topic1 = 'Maths'
topic2 = 'Geography'
_name_ ='XNAME'
_label_ ='XLABEL'
col1 ='XCOL';
*attrib student label = 'Student Name'
topic1 label = 'Maths'
topic2 label = 'Geography'
_name_ label = 'XNAME'
_label_ label = 'XLABEL'
col1 label = 'XCOL';
*label _name_ =' '
_label_=' ';
*attrib _name_ label = ''
_label_ label = '';
attrib _all_ label =' ';
run;
proc print data=class_t noobs;
run;
proc print data=class_t label noobs;
run;
There are two basic approaches to dealing with assigning labels to variables other than _name_ variable.
The Proc Transpose option LABEL sets the value of the label for the _name_ variable.
If you are using the ID option you can include another variable that holds the intended label for the transposed variable names created by use of ID.
Or use Proc DATASETS to add labels to the created transposed data after the set is created.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.