DATA Step, Macro, Functions and more

how can i sort the dataset in datastep?

Reply
SAS Employee
Posts: 73

how can i sort the dataset in datastep?

Hi all,

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

regards,
pavan.
Super User
Posts: 5,434

Re: how can i sort the dataset in datastep?

Posted in reply to Pavan_SAS
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
N/A
Posts: 0

Re: how can i sort the dataset in datastep?

Posted in reply to Pavan_SAS
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
Super User
Posts: 5,434

Re: how can i sort the dataset in datastep?

Posted in reply to deleted_user
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
N/A
Posts: 0

Re: how can i sort the dataset in datastep?

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
Ask a Question
Discussion stats
  • 4 replies
  • 133 views
  • 0 likes
  • 3 in conversation