New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 787 views
  • 2 likes
  • 2 in conversation