BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Derek_Hu
Calcite | Level 5

Hi,
I can't figure out the reason for an unwanted result.

Here is my code and result. Why VSSEQ=0.1 is behind VSSEQ = 2 and 3 in the result? 

Thanks for your help!

 

data vitals;
input VSSEQ VSTEST $ VISIT;
datalines;
0.1 SBP 0
0.1 SBP 2
0.1 SBP 3
2 DBP 0
2 DBP 1
2 DBP 2
2 DBP 3
3 PULSE 0
3 PULSE 1
3 PULSE 2
run;

 

proc report data=vitals;
column VSSEQ vstest visit;
define VSSEQ /order ORDER=FORMATTED;
define vstest /order order=data;
define visit /order order=data;
run;

 

Derek_Hu_0-1715325177388.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @Derek_Hu,

 

The documentation of the ORDER= option explains it:

FORMATTED

orders values by their formatted (external) values. If no format has been assigned to a class variable, then the default format, BEST12., is used.

The BEST12. formatted values of 0.1, 2 and 3 are:

------------
         0.1
           2
           3
------------

So they are right-aligned in a 12-character field and the '0' (ASCII code 48) of '0.1' at character position 10 is sorted after the leading blank ' ' (ASCII code 32) at the same position for the integer values.

 

Use ORDER=INTERNAL to obtain the desired numerical sort order.

View solution in original post

4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hi @Derek_Hu,

 

The documentation of the ORDER= option explains it:

FORMATTED

orders values by their formatted (external) values. If no format has been assigned to a class variable, then the default format, BEST12., is used.

The BEST12. formatted values of 0.1, 2 and 3 are:

------------
         0.1
           2
           3
------------

So they are right-aligned in a 12-character field and the '0' (ASCII code 48) of '0.1' at character position 10 is sorted after the leading blank ' ' (ASCII code 32) at the same position for the integer values.

 

Use ORDER=INTERNAL to obtain the desired numerical sort order.

Derek_Hu
Calcite | Level 5
Thanks. That means ORDER=FORMATTED is equal to using the PUT function to convert the data into a specified format, instead of keeping the variable as numeric with the appearance of BEST12.. Please correct me if anything is wrong.
FreelanceReinh
Jade | Level 19

@Derek_Hu wrote:
Thanks. That means ORDER=FORMATTED is equal to using the PUT function to convert the data into a specified format, instead of keeping the variable as numeric with the appearance of BEST12.. Please correct me if anything is wrong.

I wouldn't say it is "equal". Using a corresponding character variable created by the PUT function would result in the same sort order. However, this character variable could not be used, say, in arithmetic calculations in a COMPUTE block -- unlike the existing numeric variable, formatted or not.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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