SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data fruit;
merge apple and orange;
by size;
run;

proc sort data=apple;
by size;
run;

proc sort data=orange;
by size;
run;

if I have the code above, is the sorting gonna be done after merging or it can automatically sort first as I am aware that is sas sorting must be done before merging .... unfortunately the code I am encounterin is like the above, I am puzzled if it needs changing or sas would do sorting before merging

3 REPLIES 3
japelin
Rhodochrosite | Level 12

If you want to merge, you must do SORT first.

proc sort data=apple;
by size;
run;

proc sort data=orange;
by size;
run;

data fruit;
merge apple orange;
by size;
run;

Also, you do not need "and" in merge statement. Just describe them space-separated.

 

Kurt_Bremser
Super User

There is no PROC MERGE, so your subject line is misleading.

The data step BY(!) will only work if all incoming datasets are properly sorted. This means that your following SORT steps are unnecessary.

Amir
PROC Star

Hi,

 

Yes you are correct, data sets need to be in the same sort order as the variables in the by statement, so this will typically necessitate the data to be sorted before merging, unless the data was received in the required sort order, in which case the proc sort steps are not required at all (before or after the merge).

 

 

Kind regards,

Amir.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1021 views
  • 5 likes
  • 4 in conversation