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

Hi all,

I want to merge two data sets in SAS. I want to show by using example:

Group Value
    A       10
    A        8
    A        6
    B        7
    B        9
    B       11

it is my first data set. I have the second dataset as well:

Group Volume
    A       2
    B       3

I want to merge these two data sets. The result should be:

Group Value Volume
    A       10         2
    A       8           2
    A       6           2
    B       7           3
    B       9           3
    B      11          3

I hope, i can explain it. Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Miracle
Barite | Level 11

if by datastep

data first;
input Group $ Value @@;
datalines;
A 10 A 8 A 6 B 7 B 9 B 11
;
run;
data second;
input Group $ Volume @@;
datalines;
A 2 B 3
;
run;
proc sort data=first; by Group; run;
proc sort data=second; by Group; run;
data want; merge first second; by Group; run;
proc print data=want noobs; run;

View solution in original post

2 REPLIES 2
Miracle
Barite | Level 11

if by datastep

data first;
input Group $ Value @@;
datalines;
A 10 A 8 A 6 B 7 B 9 B 11
;
run;
data second;
input Group $ Volume @@;
datalines;
A 2 B 3
;
run;
proc sort data=first; by Group; run;
proc sort data=second; by Group; run;
data want; merge first second; by Group; run;
proc print data=want noobs; run;
Khaladdin
Quartz | Level 8

Thank you very much. it works

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Discussion stats
  • 2 replies
  • 1299 views
  • 1 like
  • 2 in conversation