Character Variables Range

Reply
Frequent Contributor
Posts: 75

Character Variables Range

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

Respected Advisor
Posts: 4,930

Re: Character Variables Range

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
Super User
Super User
Posts: 7,074

Re: Character Variables Range

'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' .

Frequent Contributor
Posts: 75

Re: Character Variables Range

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!

Super User
Super User
Posts: 7,074

Re: Character Variables Range

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

Ask a Question
Discussion stats
  • 4 replies
  • 200 views
  • 0 likes
  • 3 in conversation