Gracefully terminate a SAS program when a particular dataset is created with zero observations

%macro zeroobs(l,d);
%local l d lib dsn nobs;
%let lib = %upcase(&l);
%let dsn = %upcase(&d);
   proc sql noprint;
         select nobs into :nobs separated by " "
         from dictionary.tables
         where libname = &lib and memname = &dsn;
   quit;
%if &nobs = 0 %then %do;
   ods html close;
   ods preferences;
   ods html;
   data zeroobs;
         message = 'NO RECORDS RETURNED - ENDING PROGRAM';
   run;
   proc print data=zeroobs noobs;
         title;
   run;
%abort cancel;
%end;
%mend zeroobs;

%zeroobs('work','courses');