DATA Step, Macro, Functions and more

How to deal with a file name ends with a number in PROC FORMAT?

Reply
Super Contributor
Posts: 297

How to deal with a file name ends with a number in PROC FORMAT?

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.

Super User
Posts: 17,840

Re: How to deal with a file name ends with a number in PROC FORMAT?

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.

Super User
Posts: 5,083

Re: How to deal with a file name ends with a number in PROC FORMAT?

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.

 

Super User
Posts: 10,500

Re: How to deal with a file name ends with a number in PROC FORMAT?

[ Edited ]

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.

Super Contributor
Posts: 297

Re: How to deal with a file name ends with a number in PROC FORMAT?

Thanks for the great suggestion.

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 382 views
  • 5 likes
  • 4 in conversation