DATA Step, Macro, Functions and more

base sas

Reply
Super Contributor
Posts: 272

base sas

Dear ,

 

Ihave two large SDTM data sets. I need to find the number of subjid which are present in one datset and not in other dataset and viceversa. Is there any code that I can use.Thanks.

 

Thanks

PROC Star
Posts: 1,760

Re: base sas

Posted in reply to knveraraju91

If you can index your tables by subjid, you can then do this:

 



data WANT;
  merge TAB1(keep=SUBJID in=A) 
             TAB2(keep=SUBJID in=B);
  by SUBJID;
  if first.SUBJID and not(A and B);
  if A then SOURCE='TAB1'; else SOURCE='TAB2';
run;


 
Respected Advisor
Posts: 4,925

Re: base sas

Posted in reply to knveraraju91

Or use SQL

 

proc sql;
create table want as
select "TAB1" as source, subjid from TAB1 where subjid not in (select subjid from TAB2)
union all
select "TAB2" as source, subjid from TAB2 where subjid not in (select subjid from TAB1);
quit;
PG
Trusted Advisor
Posts: 1,117

Re: base sas

Posted in reply to knveraraju91

If you're only interested in how many distinct, non-missing SUBJIDs there are in the first dataset and not in the second and vice versa:

proc sql;
select count(subjid) as only_in_tab1
from ((select subjid from tab1)
      except
      (select subjid from tab2));

select count(subjid) as only_in_tab2
from ((select subjid from tab2)
      except
      (select subjid from tab1));
quit;
Super Contributor
Posts: 272

Re: base sas

Posted in reply to knveraraju91

Thank you all

Ask a Question
Discussion stats
  • 4 replies
  • 258 views
  • 3 likes
  • 4 in conversation