Hi, I'm confused about this question below. Any input is greatly appreciated. Thank you!
What does dataset both look like by interleaving these datasets in different order?
Data one; input lot npass; cards; 10 80 10 81 11 72 15 70 ; proc print; run; Data two; input lot pctfail; cards; 10 0.01 11 0.01 11 0.05 15 0.10 20 0.08 20 0.09 ; proc print; run;
Below is my output. It seems like the dataset is not in different order. I'm not if this answers the question above.
interleave data one two Obs lot npass pctfail 1 10 80 . 2 10 81 . 3 10 . 0.01 4 11 72 . 5 11 . 0.01 6 11 . 0.05 7 15 70 . 8 15 . 0.10 9 20 . 0.08 10 20 . 0.09
The only interpretation of "different order" in that question that makes any sense is the order that the datasets are listed on the SET statement.
You could run:
data want;
set one two;
by lot;
run;
or you could run
data want;
set two one;
by lot;
run;
If there are any values of LOT that are common to both of the two datasets (such as 10,11 and 15) then the relative order of the observations that are read from ONE and those read from TWO will change when the order that the datasets are listed in the SET statement is changed.
@Amy0223 wrote:
Hi, I'm confused about this question below. Any input is greatly appreciated. Thank you!
What does dataset both look like by interleaving these datasets in different order?
I don't understand the question either. Makes no sense to me.
Before you can write any code, you have to know what the problem is you are trying to solve. So step #1 is to get a better explanation of what the actual question means.
You didn't show your code that combined ONE and TWO to generate the output you showed. But I do know what it is:
data one ;
input lot npass ;
cards ;
10 80
10 81
11 72
15 70
;
run ;
data two ;
input lot pctfail ;
cards;
10 0.01
11 0.01
11 0.05
15 0.10
20 0.08
20 0.09
;
run ;
data interleave ;
set one two ;
by lot ;
run ;
This is exactly the process called in the SAS argot "interleaving". The output results you see are exactly those obtained when SAS interleaves sorted data sets by a common key.
Now pray tell what you find "confusing" about it and what you mean by "it seems like the dataset is not in different order". The output of interleaving is always in the same order as the data sets interleaved. What did you expect?
Kind regards
Paul D.
The only interpretation of "different order" in that question that makes any sense is the order that the datasets are listed on the SET statement.
You could run:
data want;
set one two;
by lot;
run;
or you could run
data want;
set two one;
by lot;
run;
If there are any values of LOT that are common to both of the two datasets (such as 10,11 and 15) then the relative order of the observations that are read from ONE and those read from TWO will change when the order that the datasets are listed in the SET statement is changed.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.