what exactly does label do, rename a variable? seems not from the documentation and I dont get it, please see my code included.. my questions is:
1. Segment="Segment" - what does label like this mean? it is the same variable name.. this means label is not just plainly rename
2. label LONG_RUN_pd="Long run default rate";- before this point, I dont have a LONG_RUN_pd variable, is this line creating a new variable LONG_RUN_pd? why then immediately rename it to "Long run default rate"
also if this is create the new variable LONG_RUN_pd, is it plainly a null column here?
3. sub_segment="Description" - what is this if not renaming sub_segment to "Description"
Segment="Segment" - what does label like this mean? it is the same variable name.. this means label is not just plainly rename
This is an assignment statement, nothing to do with labelling. You are assigning the value Segment to a variable called Segment. Run this program. It will create a one row table containing a variable called Segment with the assigned value of Segment.
data test;
Segment="Segment";
run;
proc print;
run;
Now add a label to Segment and run this program:
data test;
label Segment = "My Segment";
Segment="Segment";
run;
proc print label;
run;
You will see in the PROC PRINT output that instead of the variable name as the column heading SAS now uses the label. That's all a label is - a (longer) description of the actual variable name for use in reporting and analysis.
Labels are not "renaming" in any way, shape or form.
Labels for variables (data sets can have labels also) come in two flavors: default and 'as used' (my term). Default is the permanent label assigned to a variable, which may be when created such as in a data set with a Label or Attribute statement, assigned when created by a procedure (look at the label for _name_ from Proc Transpose for example), or when modified in an existing data set with Proc Datasets. If nothing else is assigned the "label" is the variable name. Many procedures will display the label, or some characters of the label, in procedure output.
If you don't want to use the current label in a specific procedure, maybe it is too long for the display you want or you are using the variable to mean something else temporarily, you can assign a label that is only used for that procedure with a local Label statement or other output option.
Sometimes people will assign a label that is the same as the variable name to ensure display case. The variable might actually be created as "segment" and the lower case version would be used. So Label segment="Segment" means that the upper case version appears in most output. Or perhaps some organization has rule about code explicitly providing labels for some reason.
Label, just like Format and a number of other statements will create a variable if one by that name does not exist. It will by default be a numeric and have a missing value assigned. If the variable is not used anywhere you are likely to see a note in the log similar to:
NOTE: Variable y is uninitialized.
Ancient history: Once upon a time very few programming languages allowed variables to have names more than X characters long, where X varied by operating system and language. For example one flavor of BASIC I used had a 2 character limit for variable names: One Upper case letter optionally followed by a digit. SAS provided the LABEL as a method of displaying more information than could be held in the 8 character limit of variable names which did not allow any characters other than Letter, digit or _ character. The label still allows displaying longer than the 32 character limit of variables.
Labels can help document you data when they are meaningful. There is nothing like inheriting a data set with 50 variables named things like p_22_r_17 with no description (label) and trying to figure what they are supposed to represent.
@Kurt_Bremser wrote:
MAI Business Basic?
Don't remember the actual name, BASIC on an IBM-360 circa 1977.
While a variable name (which you use to address the variable in code) in SAS is limited to 32 characters, a variable label can contain up to 256 characters of free text. The label can be used as column header instead of the name (e.g. when you use PROC PRINT with the LABEL option).
Labels are described here: LABEL Statement
BIG hint: reading the documentation is in fact helpful.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.