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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 4229 views
  • 5 likes
  • 4 in conversation