Try something like this:
https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p011imau3tm4jen1us2a45cyenz9.htm&docsetVersion=9.4&locale=en
It gets you fairly close but I'll leave the modifications up to you.
%macro drive(dsn);
%let dsid=%sysfunc(open(&dsn));
%if &dsid ne 0 %then %do;
%let cnt=%sysfunc(attrn(&dsid,nlobs));
%let rc=%sysfunc(close(&dsid));
%if &cnt ne 0 %then %do;
proc print data=&dsn;
title "This is data from data set &dsn";
run;
%end;
%end;
%else %do;
data missing;
Error_Message = "Data set &dsn is empty.";
run;
title;
proc print data=missing label;
label error_message = '';
run;
proc sql noprint;
drop table missing;
quit;
%end;;
%mend drive;
%drive(sashelp.class);
%drive(demo);
... View more