Help using Base SAS procedures

Multiple proc sorts

Reply
Occasional Contributor
Posts: 11

Multiple proc sorts

I would like to sort more than one dataset with a common by variable in one proc sort.

is this possible?
if so, please assist with syntax.
Super User
Posts: 5,254

Re: Multiple proc sorts

No.
If you want to minimize coding you cold wrap your sort into a macro.
/Linus
Data never sleeps
Super Contributor
Super Contributor
Posts: 3,174

Re: Multiple proc sorts

Consider declaring a SAS macro variable (or a SAS79-style macro statement), such as:

%LET BY_VARS = A B C; - macro variable declared
BY &BY_VARS; - now reference the macro variable

..or..

MACRO _BYVARS A B C % - macro statement declared
BY _BYVARS; - now reference the macro statement


Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Multiple proc sorts

try this:

%macro st (ds);
proc sort data = &ds;
by var1 var2 var3;
run;
%mend;

%st(dataset1);
%st(dataset2);
.
.
.


GL
Respected Advisor
Posts: 3,886

Re: Multiple proc sorts

If you have to sort all these data sets in order to merge them using a common key then consider using PROC SQL instead of a data step as there data sets don't need to be pre-sorted for joining them.
Ask a Question
Discussion stats
  • 4 replies
  • 342 views
  • 0 likes
  • 5 in conversation