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

Hi All 🙂

 

I have the following problem. I have two datasets have1 and hav1 as below

 

data have1;
   input A $ B C;
   datalines;
   Peter 10 100
   Peter 20 300
   Anna  36 900
   Kelly 80 700
   Kelly 40 400
   Kelly 70 800
   Max   45 951
   Max   12 752
   ;

data have2;
   input A $ B C;
   datalines;
   Peter 10 100
   Anna  36 900
   Kelly 80 700
   Kelly 70 800
   Max   12 752
   James 46 943
   ;

Now I want to extract the observations in have1 that do not exist in have2, which in this case makes my WANT dataset looking like this

 

data want;
input A $ B C;
   datalines;
Peter 20 300
Kelly 40 400
Max   45 951
   ;

Thank you in advance 🙂

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

SQL has a nice except join for this:

proc sql;
  create table WANT as 
  select  A,B,C
  from    HAVE 1
  except select A,B,C from HAVE2;
quit;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

SQL has a nice except join for this:

proc sql;
  create table WANT as 
  select  A,B,C
  from    HAVE 1
  except select A,B,C from HAVE2;
quit;
Jagadishkatam
Amethyst | Level 16
consider that both the datasets have1 and hav1 are sorted by variables A and B.

data want;
merge have1(in=a) hav1(in=b);
by A B;
if a and not b;
run;
Thanks,
Jag
PeterClemmensen
Tourmaline | Level 20

Very cool, thank you both 🙂

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 791 views
  • 1 like
  • 3 in conversation