SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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