BookmarkSubscribeRSS Feed
Pavan_SAS
SAS Employee
Hi all,

Can any one tell me, how can i sort the dataset in datastep (without proc sort).

regards,
pavan.
4 REPLIES 4
LinusH
Tourmaline | Level 20
The most obvious solution (for me) is to store the data in a SPDE (or SPDS if thats an option at the libname, and do a SET BY (which will result in a implicit sort on the BY variables). I'm not sure if this can be done with other techniques, but why...?

Regards,
Linus
Data never sleeps
deleted_user
Not applicable
a call routine may help;
like documented for CALL SORTC at http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a003106052.htm .

Good luck
PeterC
LinusH
Tourmaline | Level 20
I didn't know about this one, really neat. Still, I can't see how you can easily sort a whole table, at least if it has many rows and columns. The question is what you want to accomplish.

/Linus
Data never sleeps
deleted_user
Not applicable
I don't see the point either.

Perhaps original poster expects to start an independant SAS session to sort the data and provide a signal when that is completed and the data available. However, I see no way for a data step compiler to tolerate the scenario. (or should a set of scl-type functions keep trying to open the data, then extract items of data without the normal use of the names of the variables in the sorted table 😉

The CALL SORTx() routines provide limited functionality(1 vector at a time), but that reflects the limited definition of the original poster's enquiry.
Of course, the multiple columns of information could be "ordered" if the data set to be sorted could be loaded into a hash table, keyed by the required sort by-variables. Again, that is not the explicitly requested solution.

I don't see how it helps to be able to sort a "sas data set" after the data step has started, that is an unknown requirement before the data step has started, and that must be completed before the data step has finished! But then, I didn't ask the question.
I await with interest for some explanation of the purpose of this requirement.

PeterC

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1144 views
  • 0 likes
  • 3 in conversation