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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 444 views
  • 2 likes
  • 4 in conversation