BookmarkSubscribeRSS Feed
cosmid
Lapis Lazuli | Level 10

Hi,

 

When referencing a character format name, is the $ required?

 

Example:

proc format lib=formtlib;

  value jobfmt 'M' = 'Manager'

                       'E' = 'Employeed';

run;

 

If trying to associate the jobfmt with a variable in a format statement:

format jobtitle $jobfmt.;

 

is the $ required for jobfmt or optional?

 

Thanks

 

 

3 REPLIES 3
SASKiwi
PROC Star

It would be a lot quicker to test for yourself. You won't be able to create the SAS format in the first place if you don't put a dollar sign in the name:

28         proc format;
29           value sexfmt
30         'F'='Female'
ERROR: The quoted string 'F' is not acceptable to a numeric format or informat.
31         'M'='Male'
32         ;
NOTE: The previous statement has been deleted.
33         run;

 

cosmid
Lapis Lazuli | Level 10
Hi SASKiwi again!

Yes, it would be quicker just to test it but I won't have access to SAS until tomorrow.

I know when assigning the format-name in the VALUE statement, you need $ for the format-name for character values. My question was, is the $ needed when you reference that format-name.

In your example, when I reference sexfmt in a format statement:
format sex $sexfmt.;

I wanted to know in that format statement, if the $ is optional or required.

Thanks again for helping me with all of my questions!
SASKiwi
PROC Star

This is the error you get if you drop the dollar sign from the format:

35         proc print data=sashelp.class;
36         format sex sexfmt.;
ERROR: You are trying to use the numeric format SEXFMT with the character variable Sex in data set SASHELP.CLASS.
37         run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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