Try this.... %macro Test;
proc sql noprint;
create table MYWANTEDTABLES as
select memname,
case when memname='FRUITS' THEN 1
when memname='VEGETABLES' THEN 3
when memname='DAIRY' THEN 5 END
as table_tag,
sum(case when memname='FRUITS' THEN 1
when memname='VEGETABLES' THEN 3
when memname='DAIRY' THEN 5 END) AS TOTAL
from sashelp.vtable
where
libname='SASHELP' and upcase(memname) in ('FRUITS','VEGETABLES','DAIRY') and memtype='DATA'
order by calculated table_tag;
quit;
/* In the step above, i assigned a coded value whenever a table exist which when I sum-up will
give me an idea which table or tables exist.
When the value of total is:
TOTAL =1 MEANS only FRUITS table exist.
TOTAL =4 MEANS FRUITS AND VEGETABLES tables exist.
TOTAL =9 MEANS FRUITS, VEGETABLES and DAIRY tables exist.
TOTAL =6 MEANS FRUITS and DAIRY tables exist.
TOTAL =8 MEANS VEGETABLES and DAIRY tables exist.
*/
%let mycount=&sqlobs.;
%put There are &mycount. tables found.;
%if %eval(&mycount.=3) %then %do;
%put You can insert the appropriate steps here.;
%end;
/* When &MYCOUNT=
3: Means all 3 tables exist.
*/
proc sql noprint;
select max(TOTAL) into: mytotal from MYWANTEDTABLES;
quit;
%let mytotal=&mytotal.;
%put &Mytotal.;
/*
MYTOTAL =1 MEANS only FRUITS table exist.
MYTOTAL =4 MEANS FRUITS AND VEGETABLES tables exist.
MYTOTAL =9 MEANS FRUITS, VEGETABLES and DAIRY tables exist.
*/
/* Assuming you want to trigger additional steps when
fruits and vegetables only exist */
%if %eval(&mytotal.=4) %then %do;
%put Insert additional codes when fruits and veges tables exist.;
%end;
%mend;
%Test;
... View more