BookmarkSubscribeRSS Feed
rinugour
Fluorite | Level 6

How would I code a merge that will write the matches of both to one data set, the non-matches from the left-most data.

3 REPLIES 3
ballardw
Super User

The devil is in the details of what you 1) mean by matched 2) what the output should look like and 3) which method you are "matching".

 

A skeleton of a data step merge that does this:

data matched notmatched;
   merge a (in=ina)
         b (in=inb)
   ;
   by byvariables;
   if ina and inb then output matched;
   else output notmatched;
run;

The in variables are temporary variables not written to output and indicate which data sets are contributing to the current observation.

 

However without details of actual data output needs given some input sets a merge may not be appropriate, or what to do with like named variables other than those used on the BY statement are important to know.

The matching is done on the values of variables on the BY statement and the data sets would need to all be sorted by the by variables prior to the merge.

anjita
Fluorite | Level 6
  1. Data one two three;
  2. Merge DSN1 (in=A) DSN2 (in=B);
  3. By ID;
  4. If A and B then output one;
  5. If A and not B then output two;
  6. If not A and B then output three;
  7. Run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 693 views
  • 0 likes
  • 4 in conversation