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

Hi,

 

I have two datasets, and i want to see what observations are in dataset2 that are not in dataset1.

How to do that ?

 My code is this 

/*proc sql ;
	create table DATASET1 as
	select distinct enrolid, code, (svcdate) as index_cpt format mmddyy10. 
	from derived._02_cpt ;
quit ;/*179*/

/*proc sql ;
	create table DATASET2 as  
	select distinct a.enrolid, min(a.index_diag, b.index_cpt) as index_date 
        format mmddyy10.
	from derived._02_tr2 as a 
	inner join derived._02_cpt2 as b 
	on a.enrolid = b.enrolid 
	where -7 le (a.index_diag-b.index_cpt) le 7
	order by a.enrolid, index_date;
quit ;/*188*/
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If your data is simple, you can so something like this

 

data data1;
a=1;output;
a=2;output;
a=3;output;
run;

data data2;
a=1;output;
a=3;output;
run;

proc sql;
   create table want as
   select * from data1
   where a not in
   (
   select distinct a from data2
   );
quit;

Otherwise, when you compare two data sets, PROC COMPARE is a pretty good place to start.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

In PROC SQL, do a FULL JOIN, the resulting data set will include all observations from both data sets, and the ones that are in one data set but not the other will be obvious.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

If your data is simple, you can so something like this

 

data data1;
a=1;output;
a=2;output;
a=3;output;
run;

data data2;
a=1;output;
a=3;output;
run;

proc sql;
   create table want as
   select * from data1
   where a not in
   (
   select distinct a from data2
   );
quit;

Otherwise, when you compare two data sets, PROC COMPARE is a pretty good place to start.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1275 views
  • 0 likes
  • 3 in conversation