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

For this question, I think it's a one-to-many merge. So I chose 3 as my answer. Can you please explain why the answer is 5? Thanks so much

Jianan_luna_2-1596161318608.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

You are correct that this is one-to-many.

The result of a one-to-many though usually reflects the number of records in the many.

This is small enough I suggest actually typing the code, though you might be able to copy and paste to your editor as I can't since you posted a picture, and run the code.

 

data  agetable;
   input name $ age;
datalines;
Bob 12
Sue  15
;
data  foodtable;
   input name $ food $;
datalines;
Bob Pizza
Bob Cupcakes
Bob Burgers
Sue Grapes
Sue Brownies
;

data both;
   merge agetable
         foodtable
   ;
   by name;
run;

You might also experiment with the way the result table looks if you change the order of the two sets on the Merge statement to verify that the same number of records results and what the order of variables in the data set might be.

View solution in original post

1 REPLY 1
ballardw
Super User

You are correct that this is one-to-many.

The result of a one-to-many though usually reflects the number of records in the many.

This is small enough I suggest actually typing the code, though you might be able to copy and paste to your editor as I can't since you posted a picture, and run the code.

 

data  agetable;
   input name $ age;
datalines;
Bob 12
Sue  15
;
data  foodtable;
   input name $ food $;
datalines;
Bob Pizza
Bob Cupcakes
Bob Burgers
Sue Grapes
Sue Brownies
;

data both;
   merge agetable
         foodtable
   ;
   by name;
run;

You might also experiment with the way the result table looks if you change the order of the two sets on the Merge statement to verify that the same number of records results and what the order of variables in the data set might be.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 680 views
  • 1 like
  • 2 in conversation