So far we have learned several different ways of getting data into SAS,
a necessary prerequisite before we can conduct any sort of analysis.
This video is all about making that data easier to read, and by extension, more useful.
As we have already seen, we often want to produce reports, or some other form of output, for others to read.
As you may have noticed, without some background knowledge about the data
a list or table full of numbers is usually not very meaningful.
However, entering variable values as character variables is time consuming,
makes for inefficient coding, and limits the kinds of analysis we’re able to conduct.
Recall the ht_wt7 data set from a previous video.
This data is perfectly valid and able to be analyzed just as it is.
But, let’s say that you want to change the appearance of this list repot in order to make it a little easier to read.
For instance, you may want more descriptive variable names.
Or, you may want the values for the variables to be more easily interpretable.
Labels alter the appearance of variable names in SAS output, but not the underlying name stored in the SAS data set.
Formats alter the appearance of variable values in SAS output, but not the underlying values stored in the SAS data set.
You can create labels and formats in DATA and PROC steps.
If you include your labels and formats in a data step they become permanently associated with the variables in the data set.
However, if you include them in a PROC step, they are only associated with the variables in the output of that specific report.
Remember that the descriptor portion of a SAS data set stores variable attributes,
such as the name, type, and length of the your variables.
You can also add labels and formats to the descriptor portion of SAS data sets in a DATA step
in order to permanently associate them with variables.
Here is the general form of the LABEL statement.
You start with the SAS keyword LABEL.
After the keyword LABEL, you enter the name of a variable that you want to label,
followed by an equals sign, and then the descriptive label you want to apply to a variable,
placed either single or double quotes.
You may label multiple variables in a single LABEL statement, and labels can be up to 256 characters long.
After a label has been permanently associated with a variable,
you may choose to view the label, or the variable name, in list reports generated by PROC PRINT.
Now, watch this demonstration
In this SAS program you will use the Import Wizard to import an excel spreadsheet called “hospital survey.”
Looking at the results from the CONTENTS procedure, you can see that this data set includes 100 observations and 16 variables.
Notice that the labels for every variable are identical to the variable names themselves, the default when imported without labels.
Also notice that in many cases the variable name is not very informative.
Let’s add labels to the variable names in a DATA step to improve readability.
Here you are telling SAS to create and new SAS data set called hospital2 and store it in the library called ntrhd.
The set statement tells SAS to get the values for the new data set from the existing data set called hospital1,
which is also stored in the library ntrhd.
Next, you use the SAS keyword LABEL, to tell SAS that you want to add a label to a variable name.
The variable name you feed in to SAS is addate.
You then tell SAS that the label for addate equals, or is, date of admission.
Similarly, the label for check1 is check-in process.
Notice that labels can be assigned to multiple variables in one statement, so there is only one semicolon.
Finally, you finish with a run statement.
As you can see, addate and check1 now have the labels you just created assigned to them.
Now let’s view the data using PROC PRINT.
And as you can see here, the labels are not used as column headings by default in the list
report that results from PROC PRINT.
However, you can tell SAS to use them by adding the LABEL option in the PROC PRINT statement.
Here you added the LABEL option to the PROC statement of the PRINT procedure.
And there they are.
Why we’re here and talking about the readability of output, did you notice that with 100 observations,
this is the largest data set you’ve used so far.
You already know how to use the VAR statement in PROC print to select and order the variables that are displayed.
But, what if you also want to select the number of observations that are displayed?
You can do that with the OBS= option in the PROC print statement.
Notice the parentheses around the entire OBS= option.
And there is the list report of the first 10 observations in your data set.
This concludes the video on labels.
Remember that labels affect the appearance of variable names in your SAS output,
but not the actual variable names in your data set. Next we will learn how to apply formats your data values.