BookmarkSubscribeRSS Feed
Kc2
Quartz | Level 8 Kc2
Quartz | Level 8

Hello,

Few weeks ago I saw that SAS has an output option that gives the number of non matching observation and writes them to a dataset.

I can not find the appropraite syntax.

The example given was that if you have dataset A and dataset B and you combine them (using merge or set) with a particular output option you can get the observations that meet your merging criteria in dataset AB1 and the nonmatching observations in datasetABnon without writtne a conditiona if statement.

I just can not find  the syntax and am wondering if anyone knows what I am referring to.

Maybe it is a new feature of 9.3.

thanks

Kamal

1 REPLY 1
Cynthia_sas
SAS Super FREQ

Hi:

There's a difference between getting the NUMBER of non-matching observations and getting the actual non-matching observations in a dataset. Which one do you really want? It almost sounds to me like you are describing (sort of ) the use of the IN= option with a SAS MERGE statement. But even with IN=, you need conditional logic to get the correct observations in the output file:

data both_ab only_a only_b;

  merge a(in=ina)

        b(in=inb); by matchvar;

  if ina=1 and inb=1 then output both_ab;

  else if ina=0 and inb=1 then output only_b;

  else if ina=1 and inb=0 then output only_a;

run;

The above code would create 3 data sets..one for the matches, one for the obs in only dataset a and the other for only the obs in dataset b.

if you wanted matches in one file and all the nonmatches in a second file, then you would do this:

data matches nonmatches;

  merge a(in=ina)

        b(in=inb); by matchvar;

  if ina=1 and inb=1 then output matches;

  else if (ina=0 and inb=1) or (ina=1 and inb=0) then output nonmatches;


run;

But then you might be referring to something else entirely. It's not clear to me from your description that you really mean the IN= option. It was just a guess on my part. To review the new features of SAS 9.3, refer to the What's New documentation in the SAS 9.3 doc. It's usually at the very beginning of the documentation, under a separate topic like "What's New in Base SAS 9.3 Procedures" or 'What's New in SAS 9.3 Data Set Options". You can search for those topics in the Help files to find them.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1 reply
  • 894 views
  • 0 likes
  • 2 in conversation