/***************************************************************************************************************** SAS file name: dataset_exist.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to check if a SAS data set exists. Author: Peter Clemmensen Creation Date: 07/07/2019 This program supports the example page "Check if SAS Data Set Exists" on SASnrd.com *****************************************************************************************************************/ /* Example data */ data a; a=1; run; /* In a Data Step */ data _null_; if exist("a") then put "It's there!"; else put "It's not there!"; run; /* In a macro */ %macro check(ds); %if %sysfunc(exist(&ds.)) %then %do; %put Its There!; %end; %else %do; %put Its Not There!; %end; %mend check; %check(a); /* In open code */ %if %sysfunc(exist(work.a)) %then %do; %put Its There!; %end; %else %do; %put Its Not There!; %end;