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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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