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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 770 views
  • 0 likes
  • 2 in conversation