BookmarkSubscribeRSS Feed
apple
Calcite | Level 5

proc format;

value $LOAN_NUM_YR_LFT_CNT

'0'='0'

'0'<-'10'='0<-10'

'10'<-'29'='10<-29'

'30'-'35'='30-35'

'35'<-high='Above 35'

;

run;

When I use this format for a character variable, a separate column is created for 3 when it should be included in '0<-10', how to correct this error?

Thanks

4 REPLIES 4
PGStats
Opal | Level 21

You are asking for trouble; but anyway, if your strings all represent integers between 0 and 99, I think you could get away with:

proc format;

value $LOAN_NUM_YR_LFT_CNT

'0'='0'

'1'-'9', '10'='0<-10'

'11'-'29'='10<-29'

'30'-'35'='30-35'

'36'-high='Above 35'

;

run;

The result will depend on the character collating sequence in use.

PG

PG
Tom
Super User Tom
Super User

'3' is not included in any of the ranges you have listed.

'3' is larger than '10' since '3' comes after '1' .

'3' is larger than '29' since '3' comes after '2'.

'3' is smaller than '30' since ' ' (space) comes before '0' .

apple
Calcite | Level 5

Thanks for the reply.

But I don't understand how SAS read range for character variable format.

"'3' is smaller than '30' since ' ' (space) comes before '0' ." I don't understand.

Can someone explain things more clearly so I won't make the same mistake?

Thank you a lot!

Tom
Super User Tom
Super User

It is like looking up a word in a dictionary.  Just like 'A ' is smaller than 'AZ'.

To see the relative order of all characters look at a chart of ASCII codes. ASCII Code - The extended ASCII table

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
  • 1407 views
  • 0 likes
  • 3 in conversation