BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data fruit;
merge apple and orange;
by size;
run;

proc sort data=apple;
by size;
run;

proc sort data=orange;
by size;
run;

if I have the code above, is the sorting gonna be done after merging or it can automatically sort first as I am aware that is sas sorting must be done before merging .... unfortunately the code I am encounterin is like the above, I am puzzled if it needs changing or sas would do sorting before merging

3 REPLIES 3
japelin
Rhodochrosite | Level 12

If you want to merge, you must do SORT first.

proc sort data=apple;
by size;
run;

proc sort data=orange;
by size;
run;

data fruit;
merge apple orange;
by size;
run;

Also, you do not need "and" in merge statement. Just describe them space-separated.

 

Kurt_Bremser
Super User

There is no PROC MERGE, so your subject line is misleading.

The data step BY(!) will only work if all incoming datasets are properly sorted. This means that your following SORT steps are unnecessary.

Amir
PROC Star

Hi,

 

Yes you are correct, data sets need to be in the same sort order as the variables in the by statement, so this will typically necessitate the data to be sorted before merging, unless the data was received in the required sort order, in which case the proc sort steps are not required at all (before or after the merge).

 

 

Kind regards,

Amir.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1183 views
  • 5 likes
  • 4 in conversation