Suppress variable labels in SAS procedures

10

Sometimes a small option can make a big difference. Last week I thought to myself, "I wish there were an option that prevents variable labels from appearing in a table or graph." Well, it turns out that there is!

I was using PROC MEANS to display some summary statistics, and the output was starting to get quite wide. For example, the following table has eight columns, including the labels for each variable:

proc means data=sashelp.iris N Mean StdErr CLM Std;
var SepalLength SepalWidth;
run;

Now, I'm sure that the procedure "means" well (pun intended), but I don't need to see the labels for these variables. I can probably remember that the SepalLength variable is a measurement of the "Sepal Length"! On a whim, I searched for the terms "PROC MEANS" and "NOLABEL" and—Awesome!—was led to a SAS Knowledge Base article entitled "New option to suppress variable labels in PROC MEANS."

It turns out that PROC MEANS supports a NOLABELS option, which means that I can suppress the unnecessary column of output:

proc means nolabels data=sashelp.iris N Mean Std StdErr CLM;
var SepalLength SepalWidth;
run;

But it turns out that my good fortune was just beginning. The same article mentions that there is a NOLABEL global system option that suppresses the use of labels in all SAS procedures until you enable the option again. This means that I no longer have to use a LABEL= data set option within each procedure. For example, if I want the variable names to appear on the axis of a ODS graphic, I used to write statements like the following:

proc sgplot data=sashelp.iris;
label SepalLength= SepalWidth=;  /* <== suppress labels for these variables */
scatter x=SepalLength y=SepalWidth / group=Species;
run;

However, with the NOLABEL option, I can write this more succinctly:

options nolabel;   /* <== suppress labels for all variables */
proc sgplot data=sashelp.iris;
scatter x=SepalLength y=SepalWidth / group=Species;
run;

In a similar way, I can suppress the labels in parameter estimate tables and other tables output by SAS procedures:

options nolabel;   /* <== suppress labels for all variables */
proc reg data=Sashelp.iris;
   model SepalLength = SepalWidth / clb stdb;
   ods select ParameterEstimates;
run;
options label;     /* <== re-enable labels */

I like it. So here's a big "shout out" to whomever at SAS was involved in implementing this option. Sometimes a small option can makes a big difference.

Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

10 Comments

  1. You can remove labels from a list of variables using the ATTRIB statement.

    attrib covar: label=' ';
    attrib _all_ label=' ';

    This is more concise than the LABEL statement and more specific than the system option.

    • Rick Wicklin

      In PROC PRINT you can use the LABEL option to display labels instead of variable names. Most analytical procedures (for example, regression procedures) always display variable names. If you have a procedure (such as PROC REG in this example) that displays both, you would have to modify the ODS template to suppress the column of variable names.

  2. Hafiz Hasnat Ahmad on

    Perhaps Srinu99 wanted to print a list of just labels being used in dataset. The procedure below would produce a text list of Names of variables and labels against those names
    SASWORK=own library
    saswork.COMPUSTAT5=input data set name

    Ods rtf file='D:\SASWORK\VARIABLES.rtf';
    proc contents
    data = saswork.COMPUSTAT5
    out = data_info
    (keep = label varnum);
    run;
    ods rtf close;

  3. Ruth Repchuck on

    Is there a way to suppress value labels in proc freq? I would like to see the codes rather than the labels!!

      • Ruth Repchuck on

        Thank you for your reply! I am thinking more about value labels - would like to see the code (i.e., 1 instead of Disagree). Is there an easy way to do that?

        • Rick Wicklin

          If you have questions about SAS programming, please ask them at the SAS Support Communities.

          If you don't want to see the formatted values then remove the format:
          FORMAT VAR1 VAR2;

Leave A Reply

Back to Top