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

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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