BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
john83
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.

View solution in original post

6 REPLIES 6
Patrick
Opal | Level 21

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.

yaswanthj
Calcite | Level 5

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.

Haikuo
Onyx | Level 15

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

john83
Calcite | Level 5

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

Ksharp
Super User

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

Ksharp

john83
Calcite | Level 5

Thanks Ksharp. Now I understood the difference.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 8987 views
  • 3 likes
  • 5 in conversation