01-04-2016 10:14 AM
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.
01-04-2016 10:26 AM
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.
01-04-2016 10:33 AM
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.
01-04-2016 11:52 AM - edited 01-13-2016 07:07 PM
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.