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;


 

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
  • 739 views
  • 0 likes
  • 2 in conversation