New To SAS Proc

Posts: 26

New To SAS Proc

I am running some simple descriptives for a rather large dataset.

I'll use the variable 'Q54' as an example.

Running a simple Proc Freq procedure for 'Q54'.

Q54 has 5 response options noted in the excel file as 1, 2, 3, 4, and 5.

I want to rename 1, 2, 3, 4, and 5 as satisfied, somewhat satisfied, neutral, somewhat dissatisfied, and dissatisfied, respectively.

When writing code for this using :

proc format;

value q69



I get an error term stating:

792        value q69

ERROR: The format name Q69 ends in a number, which is invalid.

Any insight as to the best way to remedy this issue?

Thanks for looking over my issue and appreciate any help.


Respected Advisor
Posts: 4,641

Re: New To SAS Proc

SAS numeric format names must start with a letter and end with a letter. So if Q54 is numeric, you could use:

proc format;

value q69fmt

1 = 'Satisfied'

2 = 'somewhat satisfied'

3 = 'neutral'

4 = 'somewhat dissatisfied'

5 = 'dissatisfied';


Note the absence of quotes around the numbers. Otherwise, if Q54 is a character variable, you need to define a character format such as:

proc format;

value $q69fmt

'1' = 'Satisfied'

'2' = 'somewhat satisfied'

'3' = 'neutral'

'4' = 'somewhat dissatisfied'

'5' = 'dissatisfied';


Note the dollar sign before the format name.


Posts: 7,356

Re: New To SAS Proc

I'd really hope sas would eventually change that limitation but, currently, the formats can't end in a number.

However, your asking about q54, but tried to call the format q69.  Was that an error in your thought process?


value q69_fmt

should work.

Super Contributor
Posts: 644

Re: New To SAS Proc

The reason SAS format names do  not end with a numeral is that the numeral at the end of the name would be interpreted as a width definition.  Thus the format use q1234. would mean use the format q and assign 1234 spaces to the display.

It would not be impossible to modify the SAS interpreter to check first to see if q1234 was a valid format but this could result in potential ambiguity.  Now that the limit has been relaxed on the length of format names it is not too much of a hardship to append one or more alpha characters so that the name does not end in a numeral.  My vote would be for the status quo.


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