BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello,

 

How to fix the following error message from SAS?  Thanks.

 

18 proc format;
19 value $AGEgroup4 1="18<AGE<24" 2="25<AGE<44" 3="45<AGE<64" 4="65<AGE<120" ;
ERROR: The format name AGEGROUP4 ends in a number, which is invalid.

4 REPLIES 4
Reeza
Super User

Don't end the format name in a number. Adding a number works. 

 

If this is an automated procedure of some sort, it becomes more difficult as you'll need to test the last character to check if it's numeric. ANYDIGIT() function can be used to check if a number is included in some text.

Astounding
PROC Star

As Reeza mentioned, the error message is pretty explicit.  $AGEgroup4 is an illegal name for a format.  You could name the format $AGEgroup4_ instead, if you wanted to.

 

There's actually a good reason why format names are not permitted to end in a number.  It allows you to control how many character to print when applying the format.  For example, suppose you had a format named $AGEgroup.  You could apply that format using:

 

format varname $AGEgroup.;

 

However, you could also apply that format in the following way:

 

format varname $AGEgroup2.;

 

This last FORMAT statement requests that the $AGEgroup format be used, but only print the first two characters of the formatted value.  By making it illegal to create a format with a name that ends in a number, you gain the flexibility to add a number later when applying the format, to control how many characters will print.

 

ballardw
Super User

We get around this in my shop by either naming the agegroup format with something related to which analysis it is most used with or some description. In your example we would name the format something like Age_4groups to indicate the purpose is to have 4 groups. 

We have some based on intervals so we use Age5Yr or Age10Yr to indicate the break points are at 5 or 10 year intervals.

ybz12003
Rhodochrosite | Level 12

Thanks for the great suggestion.

 

 

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
  • 4 replies
  • 5610 views
  • 5 likes
  • 4 in conversation