/* 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;
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;
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;
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: