Hi if I have created an index for my dataset, does that mean sorting is not required anymore for this dataset prior to merging? As I see this in some programs with index where sort is not added before merge..
I've never used indexes for sorting. Indexes are only good when you need to extract a small (read: 10% or less) subset of the dataset. In all other cases, they only add additional I/O and therefore processing time.
Yes. Though, all the data sets in the Merge Statement must be either sorted or have an appropriate index.
See the small example below
data one;
input x y1;
datalines;
1 10
3 20
2 30
;
data two;
input x y2;
datalines;
1 40
2 50
3 60
;
proc datasets lib = work nolist;
modify one;
index create x;
run;quit;
data want;
merge one two;
by x;
run;
Even if it's technically possible to merge on indexed variables, it's seldom a good idea.
In most situations sorting is much faster.
I've never used indexes for sorting. Indexes are only good when you need to extract a small (read: 10% or less) subset of the dataset. In all other cases, they only add additional I/O and therefore processing time.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.