DATA Step, Macro, Functions and more

sas output options

Contributor Kc2
Posts: 31

sas output options


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.



Posts: 8,745

Re: sas output options


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;


The above code would create 3 data 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;


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.


Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation