BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmytroYermak
Lapis Lazuli | Level 10

Hi all,

 

Could you please say what is the context in the "SORTEDBY=_NULL_" (unfortunately I can not ask the author) in the following code:

 

DATA test (SORTEDBY=_NULL_);
  SET pretest;
RUN;

 

The dataset pretest was previously sorted by one variable.

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

As the SORTEDBY= Data Set Option Documentation says it "removes any existing sort indicator." 🙂

 

A small example demonstrates the option

 

data SomeData;
input x @@;
datalines;
3 2 5 1 6 4 8 5
;

proc sort data=SomeData;
   by x;
run;

/* SAS knows that SomeData is sorted (Sorted=Yes) */
proc contents data=SomeData;
run;

/* Sortedby=_null_ forces SAS to forget the sort information (Sorted=No) */
data test(sortedby=_null_);
   set SomeData;
run;
proc contents data=test;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

As the SORTEDBY= Data Set Option Documentation says it "removes any existing sort indicator." 🙂

 

A small example demonstrates the option

 

data SomeData;
input x @@;
datalines;
3 2 5 1 6 4 8 5
;

proc sort data=SomeData;
   by x;
run;

/* SAS knows that SomeData is sorted (Sorted=Yes) */
proc contents data=SomeData;
run;

/* Sortedby=_null_ forces SAS to forget the sort information (Sorted=No) */
data test(sortedby=_null_);
   set SomeData;
run;
proc contents data=test;
run;
DmytroYermak
Lapis Lazuli | Level 10

Thank you, draycut. I just do not understand for what was it needed that "SAS to forget the sort information"...

Tom
Super User Tom
Super User

In that step it is not needed since SAS will not be storing any SORTEDBY information for a dataset created in that way.

 

Perhaps they had a previous process that did generate the data in a sorted order and they wanted to force SAS to store the fact it was sorted.  So they were in the habit of using the SORTEDBY= dataset option and instead of removing it totally they just set the list of variables to _NULL_.

Amir
PROC Star

Hi,

 

Taken from the documentation:

 

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000131184.htm

 

removes any existing sort indicator

 

 

Regards,

Amir.

 

 

 

 

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
  • 4 replies
  • 1430 views
  • 3 likes
  • 4 in conversation