Completely missed what was hidden in that %SYSFUNC avalanche. To check if datasets exist, do a SELECT in SQL from DICTIONARY.TABLES; or (even better) use SASHELP.VTABLE in a DATA _NULL_ step where you decide for which you create the copy code, either with CALL EXECUTE or by writing to a temporary include file.
Using functions like FILENAME or OPEN in macro code can be tricky, as you MUST take care to close every handle and deassign every fileref; otherwise they accumulate and get in your way.
... View more