01-17-2013 02:27 PM
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?
01-17-2013 03:20 PM
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.
01-17-2013 03:58 PM
Perhaps the setting for this option is different in the two sessions.
orders integer values within the text by the numeric value instead of characters used to represent the numbers.
|ON||Order numbers by the numeric value. For example, "8 Main St." would sort before "45 Main St.".|
|OFF||Order numbers by the character value. For example, "45 Main St." would sort before "8 Main St.".|
01-17-2013 04:03 PM
I don't disagree with Astounding's comments but, yes, there is a work around.
input id $7.;
proc sort data=test SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=on);