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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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