turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- What is the use Equals option in proc Sort?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2012 06:29 AM

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;

Please help me.

Thank you,

John

Accepted Solutions

Solution

04-16-2012
06:43 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2012 06:43 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2012 06:43 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2012 11:31 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-17-2012 11:03 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-17-2012 12:29 AM

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**

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-17-2012 03:08 AM

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

Ksharp

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-17-2012 08:00 AM

Thanks Ksharp. Now I understood the difference.