- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.