Help using Base SAS procedures

Multiple proc sorts

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

If you want to minimize coding you cold wrap your sort into a macro.
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


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

Scott Barry
SBBWorks, Inc.
Posts: 0

Re: Multiple proc sorts

try this:

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


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
  • 5 in conversation