SAS Programming

DATA Step, Macro, Functions and more
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.

 

 

 

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1980 views
  • 3 likes
  • 4 in conversation