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
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.
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.
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.
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
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
Then your famous sashelp.class must have been sorted before. The following is the difference under mine.
Ksharp
Thanks Ksharp. Now I understood the difference.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.