BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HeatherNewton
Quartz | Level 8

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
LinusH
Tourmaline | Level 20

Even if it's technically possible to merge on indexed variables, it's seldom a good idea.

In most situations sorting is much faster.

Data never sleeps
Kurt_Bremser
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1246 views
  • 2 likes
  • 4 in conversation