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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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