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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 724 views
  • 1 like
  • 4 in conversation