DATA Step, Macro, Functions and more

The management of SAS formats and Labels

Occasional Contributor
Posts: 5

The management of SAS formats and Labels

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?



Super User
Posts: 6,758

Re: The management of SAS formats and Labels

Posted in reply to new_sas_user

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.

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation