BookmarkSubscribeRSS Feed
Calcite | Level 5

In SAS language- how does one define, call and suppress formats and labels?


Where can I find examples of code and the principles behind them for "defining, calling and suppressing" formats and labels. I'm not finding any SAS statements with those words- are they synonymous for something else?




Here's the bird's eye view ...


To create your own format, use PROC FORMAT.  Besides that, you can use dozens of SAS-supplied formats.


To apply a format to a variable, use the FORMAT statement.  Similarly, to apply a label to a variable, use the LABEL statement.  When used within a SAS procedure, FORMAT and LABEL statements are assigning temporary attributes that last for the duration of that procedure.  When used within a DATA step, FORMAT and LABEL statements assign permanent attributes.


Some of the dirty details ...


Some procedures use labels automatically, and some have to be told to use labels.  For example, look at the LABEL and SPLIT= options within PROC PRINT.


Labels/formats associated with a variable to do not carry over to summary statistics based on that variable.  When PROC MEANS creates the SUM of a variable, for example, the format associated with the variable is ignored.


To remove a format associated with a variable, also use the FORMAT statement.  Just don't supply a format.  For example, this statement removes any format connected with VARNAME:


format varname;


When you create your own formats with PROC FORMAT, it's a little tricky to save them permanently.  But that might be necessary if you want to use the same format in a later program.


If you receive a data set from someone else, you may find that the data is not usable because there are formats permanently associated with some variables ... formats that were created by PROC FORMAT but not given to you along with the data set.  To get around that and be able to use the data, you have a couple of choices.  Choice 1 would be to remove formats associated with variables (such as the FORMAT statement above).  Choice 2 would be to issue a global option:


options NOFMTERR;


This tells SAS not to issue an error message if a format cannot be found.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

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
  • 2 replies
  • 3 in conversation