Hi SAS Users,
It is quite a basic question regarding merging data. But normally we may prefer using "PROC SORT with data step MERGE" to merge two or more datasets instead of using JOIN in PROC SQL, especially when it comes to huge data (cartesian join).
My question is whether we MUST PROC SORT right before we do MERGE, or we can PROC SORT previously, and we run some procedures, then we come back to MERGE without PROC SORT again.
I mean it is no harm to write a PROC SORT statement (even I deem that we can write a short macro to sort all datasets at one time) , but just of curiosity regarding parsimony thingamajig.
For example:
I PROC SORT files A,B,C by Type, then I transpose file A,B, C by Type, then I merge them together, whether I should PROC SORT AGAIN before merging or it is not a need because I already merged before transposing?
Many thanks!
Whether or not you need a sort before a merge is something the programmer has to decide, based on knowledge of what the program is doing.
If the data was sorted way up at the beginning of the program, and then you run a bunch of procedures that don't change the order of the data, then there's no need to sort again before a data step merge.
There is no need to run PROC SORT if you KNOW the data is sorted in the way you need (or it has an INDEX that can be used).
Whether or not you need a sort before a merge is something the programmer has to decide, based on knowledge of what the program is doing.
If the data was sorted way up at the beginning of the program, and then you run a bunch of procedures that don't change the order of the data, then there's no need to sort again before a data step merge.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: