Problem with proc sort in 9.3

Reply
N/A
Posts: 1

Problem with proc sort in 9.3

Dear fellow SAS users:

I am having what I'm sure is ultimately a simple and resolve-able issue.  I am working with a dataset that has a variable called "ID."  These are numeric identification numbers for units of observation that are either 2 digit or 3 digits.  In SAS 9.2, when I sort by ID, they are sorted in ascending numerical order.  In SAS 9.3, when I run the same exact code, the program seems to be going through each digit and sorting by number (e.g. 74 > 734).  Whether ID is coded as categorical or not doesn't seem to have an effect.

Does anyone know why this is happening?  Is there an easy fix?

Many thanks!

Super User
Posts: 5,083

Re: Problem with proc sort in 9.3

More than a 99% chance that your data has changed, and the results are unrelated to the release of SAS.

The results are consistent with these characteristics of the data.

In your latest result, ID is a character variable, and is left-hand-justified.  Therefore, "74" > "734".

In your earlier results, there are two possibilities.  Either ID is a numeric variable, or it is a character variable that contains a leading blank for the two-digit numbers.

PROC SORT has been working for decades.  It would be extremely surprising if something about it changed in 9.3.

Good luck.

Super User
Super User
Posts: 6,500

Re: Problem with proc sort in 9.3

Perhaps the setting for this option is different in the two sessions.

NUMERIC_COLLATION=

orders integer values within the text by the numeric value instead of characters used to represent the numbers.

ValueDescription
ONOrder numbers by the numeric value. For example, "8 Main St." would sort before "45 Main St.".
OFFOrder numbers by the character value. For example, "45 Main St." would sort before "8 Main St.".

Default:OFF
PROC Star
Posts: 7,363

Re: Problem with proc sort in 9.3

I don't disagree with Astounding's comments but, yes, there is a work around.

data test;

   input id $7.;

   cards;

22

575

57

6289

1234

12

run;

proc sort data=test SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=on);

  by id;

run;

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