Then the macro code I provided above will get you that. Below is the log from testing it.
When there was no work.data1 data set:
15 %macro dsexist(dsname=,dslib=);
16
17 %put &dslib..&dsname outputflag = %sysfunc(exist(&dslib..&dsname));
18
19 %mend;
20
21 %dsexist(dsname=data1,dslib=work);
data1.work outputflag = 0
22
When there was a work.data1 data set:
15 %macro dsexist(dsname=,dslib=);
16
17 %put &dslib..&dsname outputflag = %sysfunc(exist(&dslib..&dsname));
18
19 %mend;
20
21 %dsexist(dsname=data1,dslib=work);
work.data1 outputflag = 1
22