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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Amy0223
Quartz | Level 8
Thank you very much for your suggestion. It's good to know I'm not the only one confused by the question.
hashman
Ammonite | Level 13

@Amy0223;

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.

 

Tom
Super User Tom
Super User

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.

 

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
  • 4 replies
  • 595 views
  • 3 likes
  • 4 in conversation