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

/* Concatenate (or Union) the two data sets*/
data GroupA;
input ID$ Product$;
datalines;
A Apple
B Grapes
B Orange
C Banana
E Apple
run;

data GroupB;
input ID$ Product$ Size$;
datalines;
B Shirt S
C Pants M
D Jacket L
E Tie M
E Wallet L
run;

data concat;
set GroupA GroupB;
run;
proc sort data=concat;
by ID;
run;
/* Merge the two data sets*/
data merged;
merge GroupA GroupB;
by ID;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

SET appends data, ie stacks the datasets on top of each other.
MERGE adds data in a side to side fashion, making you data wider.

 

You SHOULD NOT be expecting the same results from the different code.


All the different options and methods are explained here:
https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n1tgk0uanvisvon1r26lc036k0w7.htm&docsetVe...

 


@mahossain wrote:

/* Concatenate (or Union) the two data sets*/
data GroupA;
input ID$ Product$;
datalines;
A Apple
B Grapes
B Orange
C Banana
E Apple
run;

data GroupB;
input ID$ Product$ Size$;
datalines;
B Shirt S
C Pants M
D Jacket L
E Tie M
E Wallet L
run;

data concat;
set GroupA GroupB;
run;
proc sort data=concat;
by ID;
run;
/* Merge the two data sets*/
data merged;
merge GroupA GroupB;
by ID;
run;


 

View solution in original post

1 REPLY 1
Reeza
Super User

SET appends data, ie stacks the datasets on top of each other.
MERGE adds data in a side to side fashion, making you data wider.

 

You SHOULD NOT be expecting the same results from the different code.


All the different options and methods are explained here:
https://documentation.sas.com/?docsetId=lrcon&docsetTarget=n1tgk0uanvisvon1r26lc036k0w7.htm&docsetVe...

 


@mahossain wrote:

/* Concatenate (or Union) the two data sets*/
data GroupA;
input ID$ Product$;
datalines;
A Apple
B Grapes
B Orange
C Banana
E Apple
run;

data GroupB;
input ID$ Product$ Size$;
datalines;
B Shirt S
C Pants M
D Jacket L
E Tie M
E Wallet L
run;

data concat;
set GroupA GroupB;
run;
proc sort data=concat;
by ID;
run;
/* Merge the two data sets*/
data merged;
merge GroupA GroupB;
by ID;
run;


 

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 439 views
  • 0 likes
  • 2 in conversation