Solved
Contributor
Posts: 35

# What is the use Equals option in proc Sort?

Can anybody please tell me the use of Equals options in the proc sort procedure?

General Form of Proc sort equals option:

Proc sort data=datasetname nodupkey equals;

by variablename;

run;

Thank you,

John

Accepted Solutions
Solution
‎04-16-2012 06:43 AM
Posts: 4,736

## Re: What is the use Equals option in proc Sort?

From the SAS documentation:

"For observations with identical BY-variable values, EQUALS maintains the relative order of the observations within the input data set in the output data set."

So let's say you sort the famous sashelp.class table by sex: There will be multiple observations for 'M' and multiple observations for 'F'. With EQUALS the order within the 'F' group and the 'M' group will be the same like in sashelp.class, with NOEQUALS the order can be different.

My assumption is (I don't know for sure) that using NOEQUALS allows SAS to use a more efficient sort algorithm, so I usally use this option value.

All Replies
Solution
‎04-16-2012 06:43 AM
Posts: 4,736

## Re: What is the use Equals option in proc Sort?

From the SAS documentation:

"For observations with identical BY-variable values, EQUALS maintains the relative order of the observations within the input data set in the output data set."

So let's say you sort the famous sashelp.class table by sex: There will be multiple observations for 'M' and multiple observations for 'F'. With EQUALS the order within the 'F' group and the 'M' group will be the same like in sashelp.class, with NOEQUALS the order can be different.

My assumption is (I don't know for sure) that using NOEQUALS allows SAS to use a more efficient sort algorithm, so I usally use this option value.

Contributor
Posts: 70

## Re: What is the use Equals option in proc Sort?

When you use NODUPRECS or NODUPKEY to remove observations in the output data set, the choice of EQUALS or NOEQUALS can affect which observations are removed.

Posts: 3,167

## Re: What is the use Equals option in proc Sort?

I can confirm Patrick's comments on the efficiency. I have read some help doc a while ago (can't find the link right now) which basically addressed that if using NOEQUALS , SAS will save some effort of putting the equals back to their original order.

Haikuo

Contributor
Posts: 35

## Re: What is the use Equals option in proc Sort?

Thanks Patrick and Yaswanthj for your replies.

Patrick, I applied proc sort on famous SASHELP.CLASS with equals and noequals options respectively as you suggested. When I compared the results , I didnt find any difference.

proc sort data=sashelp.class out=emp1 nodupkey equals;

by sex;run;

proc sort data=sashelp.class out=emp2 nodupkey noequals;

by sex;run;

Can anyone help me out .

Thank you,

John

Super User
Posts: 10,787

## Re: What is the use Equals option in proc Sort?

Then your famous sashelp.class must have been sorted before. The following is the difference under mine.

Ksharp

Contributor
Posts: 35

## Re: What is the use Equals option in proc Sort?

Thanks Ksharp. Now I understood the difference.

🔒 This topic is solved and locked.