Question: I cannot understand the difference between `interleaving` and `concatenation`

Interleaving 

```
proc sort data=ds1 
           out=ds1;
   by var1;
run;
proc sort data=ds2 
           out=ds2;
   by var1;
run;
 data testInterleaving ; 
 set ds1 ds2 ;
 run ;

```

Concatenation 

```
data testConcatenation; 
   set ds1 ds2;
run;

```

I tested these and the resulting datasets were exactly the same except for the order of observations which I think does not really matter. The two resulting datasets contain exactly the same observations. So, what is the difference, except for order?

Answer: 
SAS defines [INTERLEAVING](https://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001318366.htm) as using a BY statement with a SET statement. The included link shows two data sets, sorted by the same variable(s), generating one data set using a BY statement with a SET statement.
The data steps at the end are the exact same. You are performing the same code, it doesn't matter if you sort before hand.

What I think you mean in the interleaving is

```
data testInterleaving ;
MERGE ds1 ds2;
by var1;
run;

```

The `set` statement reads sequentially through the data sets in the order you list them. The `merge` statement compares records between the sets and puts them into the output in the order of the variable(s) in the `by` statement. I recommend looking at the SAS documentation on the `merge` statement as this is a very simplistic explanation for a very powerful tool.