BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Phil_NZ
Barite | Level 11

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!

 

 
Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

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
  • 2 replies
  • 1208 views
  • 2 likes
  • 3 in conversation