BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ajb
Obsidian | Level 7 ajb
Obsidian | Level 7

 

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

@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.

View solution in original post

5 REPLIES 5
Cynthia_sas
Diamond | Level 26
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
jklaverstijn
Rhodochrosite | Level 12

Easiliy done in SQL:

 

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

Hope this helps,

- Jan.

ajb
Obsidian | Level 7 ajb
Obsidian | Level 7


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.
PGStats
Opal | Level 21

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
jklaverstijn
Rhodochrosite | Level 12

@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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 5 replies
  • 2112 views
  • 0 likes
  • 4 in conversation