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
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.
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.
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.
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!
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.