BookmarkSubscribeRSS Feed
new_sas_user
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?

 

 

2 REPLIES 2
Astounding
PROC Star

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2943 views
  • 2 likes
  • 3 in conversation