DATA Step, Macro, Functions and more

How to print observations not in subset data set

Reply
Occasional Contributor ajb
Occasional Contributor
Posts: 18

How to print observations not in subset data set

 

Sas 9.4

 

HI,

 

So I have 2 data set.  Data set  A has 4000 observations and Data set B has 3000 observations.  I know that B is a subset of A  but I do not know which observations are in B.  How can I have SAS print the 1000 observations that are only in A?

 

Thanks in advance.

 

 

 

SAS Super FREQ
Posts: 8,740

Re: How to print observations not in subset data set

Hi:
The SAS procedures for reporting (PRINT, REPORT, TABULATE) only work with one dataset at a time. You could do a MERGE before your PRINT or REPORT step or you could join the 2 datasets with PROC SQL and generate the non-matches in an SQL report. It depends on your comfort level with the idea of MERGING before you run the report/print or whether you are more comfortable with SQL.

cynthia
Super Contributor
Posts: 408

Re: How to print observations not in subset data set

Easiliy done in SQL:

 

proc sql;
    select * from A
      EXCEPT
    select * from B;
quit;

Hope this helps,

- Jan.

Occasional Contributor ajb
Occasional Contributor
Posts: 18

Re: How to print observations not in subset data set



Is there a line of code I could use to output the results to a new data set?

I am not at all familiar with sql.
Respected Advisor
Posts: 4,641

Re: How to print observations not in subset data set

This would work, I think

 

proc sort data=a; by _all_; run;
proc sort data=b; by _all_; run;

data aMinusb;
merge a b(in=inb);
by _all_;
if not inb;
run;

proc print data=aMinusb; run;
PG
Super Contributor
Posts: 408

Re: How to print observations not in subset data set


ajb wrote:


Is there a line of code I could use to output the results to a new data set?




Yes there is: CREATE TABLE AS. Eg.

 

proc sql;
create table want as 
    select * from A
      EXCEPT
    select * from B;
quit;

Regards,

- Jan.

Ask a Question
Discussion stats
  • 5 replies
  • 312 views
  • 0 likes
  • 4 in conversation