BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello,

I know the order of simple numbers (for example: 3,9,18,21,48)

I know the order of alphabetic (for example: Luxury,Midsize,Sporty)

What is the rule to order char values : 18-19 ,19-21,21+?

What is the rule to order char values :Till 18,  18-19 ,19-21,21+?

May also explain why?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Character values are basically sorted according to the position of characters in the ASCII (Windows/UNIX) or EBCDIC (z/OS) table. But the sort order can be influenced by using alternate collating sequences for NLS support.

View solution in original post

5 REPLIES 5
ErikLund_Jensen
Rhodochrosite | Level 12

Hi @Ronein 

The sorting depends on the variable type

 

Numeric variables are internally stored as double-precision float and are sorted on the numeric value, not on the digits you see.

Character values are sorted character by character (sort on first character, then second and so on..) on the decimal value of the character. All characters (digits, space, letters etc.) have a place in the latin- or utf8 or whatever-table and are sorted according to that.

PaigeMiller
Diamond | Level 26

What is the rule to order char values :Till 18,  18-19 ,19-21,21+?

From your earlier questions ... if the above is a formatted value of a numeric variable, you have the option in many SAS PROCs (such as PROC REPORT, PROC SUMMARY, PROC FREQ and probably many others) to sort these alphabetically based upon the formatted value, or to sort them numerically based upon the unformatted numbers. In general, it makes more sense to sort formatted values by the unformatted numbers, so 18 is always greater than "Till 18". PROC SORT will always use the UNFORMATTED values.

--
Paige Miller
Ronein
Meteorite | Level 14
Thanks,
I ask about char values
Till 18, 18-19 ,19-21,21+
What is the order of them please?
Ronein
Meteorite | Level 14

I found this document that can help to understand how sas sort char values

Ronein_0-1634242019340.png

 

Kurt_Bremser
Super User

Character values are basically sorted according to the position of characters in the ASCII (Windows/UNIX) or EBCDIC (z/OS) table. But the sort order can be influenced by using alternate collating sequences for NLS support.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 5 replies
  • 1409 views
  • 1 like
  • 4 in conversation