Community talk about communities.sas.com. Meta!

SAS_merging two datasets

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

SAS_merging two datasets

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.


Accepted Solutions
Solution
‎03-25-2017 11:28 AM
Regular Contributor
Posts: 217

Re: SAS_merging two datasets

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


All Replies
Solution
‎03-25-2017 11:28 AM
Regular Contributor
Posts: 217

Re: SAS_merging two datasets

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;
Contributor
Posts: 33

Re: SAS_merging two datasets

[ Edited ]

Thank you very much. it works

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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