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

Hello!

 

I have two data sets I want to merge. One is application information, the second is registrations. There are some who registered but did not fill out an application.

 

Suppose we have:

 

Application:

 

ID  Name  ... (other variables)

1    Bob

2    Bill

3    Judy

4    John

 

 

Registration:

ID  Name ... (other variables)

1    Bob

2    Bill

3    Judy

4    John

5    Jake

6    Jack

 

I know how to merge them as such:

 

data merge;

merge application (in=a) registration (in = b);

by ID;

if a and b;

run;

 

However. I would like SAS to also give me an output dataset of those who were not in both application and registration (i.e., ID's # 5 and 6 - Jake and Jack).

 

So I'd like code to give me two datasets:

 

Merge: 


ID  Name... (other variables from both datasets)

1    Bob

2    Bill

3    Judy

4    John

5    Jake

6    Jack

 

and remainder:

 


ID  Name ...(other variables)

5    Jake

6    Jack

 

So it gives me the names of just those two where not in the application dataset as well

 

How can I do this? I've seen it before, but can't remember how to search it unfortunately.


Thanks!

Best,

Gina

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data Application;
input ID $ Name $;
datalines;
1    Bob
2    Bill
3    Judy
4    John
;

data Registration;
input ID $ Name $;
datalines;
1    Bob
2    Bill
3    Judy
4    John
5    Jake
6    Jack
;

data matches nonmatches;
merge application (in=a) registration (in = b);
by ID;
if a and b then output matches;
else output nonmatches;
run;


View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data Application;
input ID $ Name $;
datalines;
1    Bob
2    Bill
3    Judy
4    John
;

data Registration;
input ID $ Name $;
datalines;
1    Bob
2    Bill
3    Judy
4    John
5    Jake
6    Jack
;

data matches nonmatches;
merge application (in=a) registration (in = b);
by ID;
if a and b then output matches;
else output nonmatches;
run;


RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please also use the search bar, and look at the previous posts.  This merging question was asked at least 3 or 4 time yesterday and the day before, and the day before that.  Also, post test data in the form of a datastep!  You can use the alias to output whre you want e.g.: (and I have not test data to check this on):

data inboth other;
  merge first (in=a) second (in=b);
  by keyvariable;
  if a and b then output inboth;
  else output other;
run;

 

ginak
Quartz | Level 8

Thank you!! Yes, it was late at night and I tried but wasn't sure what keywords exactly to use 😞 Good advice re formatting w/ a data step. Will note.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 503 views
  • 3 likes
  • 3 in conversation