Hi RW9,
Yes indeed, and interesting...
I need a macro, because in my case (see below ) I want something generic where AE dataset may or may not have all the variables (depending on studies ) . Your proposal is also a solution and looks more elegant....
%macro test(lib=)/ minoperator;
%global listvar;
proc sql;
select distinct quote(compress(name)) into :listvar separated by ' '
from sashelp.vcolumn
where libname="%upcase(&lib.)" and memname="AE";
quit;
proc sql;
*1. Check for xxterm vs xxcod (term,prefered_term);
%if AEDECOD in ( &listvar.) and AEBODSYS in ( &listvar.) %then %do;
create table ae_uniq_decod_bodsys as
select AEDECOD,AEBODSYS
from ae
group by AEDECOD
having (count( distinct AEBODSYS) gt 1 ) ;
%end;
%if AEDECOD in ( &listvar.) and AESOC in ( &listvar.) %then %do;
create table ae_uniq_decod_bodsys as
select AEDECOD,AESOC
from ae
group by AESOC
having (count( distinct AESOC) gt 1 ) ;
%end;
%if AESOC in ( &listvar.) and AESOCCD in ( &listvar.) %then %do;
create table ae_uniq_decod_bodsys as
select AESOC,AESOCCD
from ae
group by AESOC
having (count( distinct AESOCCD) gt 1 ) ;
%end;
...same logic for the cases below...
create table ae_uniq_llt_lltcd as
select AELLT,AELLTCD
from ae
group by AELLT
having (count( distinct AELLTCD) gt 1 ) ;
create table ae_uniq_decod_ptcod as
select AEDECOD,AEPTCD
from ae
group by AEDECOD
having (count( distinct AEPTCD) gt 1 ) ;
create table ae_uniq_bodsys_bodsyscd as
select AEBODSYS,AEBODSYSCD
from ae
group by AEBODSYS
having (count( distinct AEBODSYSCD) gt 1 ) ;
quit;
%mend test;
Here data will only be created if condition is true...
The previous example was written to understand why it didn't work as expected....
Thanks
saskapa
... View more