Hi All ,
The Following code in my program gives me the weird error messages and sometime it runs without any error and most of the time ended up in log file with error .
/* ************************************** MACRO to Ensure Not to print If the Dataset is empty ********************/
%macro ChkDSEmpty(Table_Name);
/* Init check flag */
%let dsempty=0;
/* create empty test data set by removing all records */
data Table_Name;
set Table_Name;
run;
/* Check for empty data */
data _null_;
if eof then
do;
call symput('dsempty',1);
put 'NOTE: EOF - no records in data!';
end;
stop;
set &Table_Name end=eof;
run;
%mend ChkDSEmpty;
%ChkDSEmpty(SOURCEDUPLICATE);
/******************************** 1094_SUMMARY_REPORTS - creation ******************************/
%macro Export;
%if &dsempty. %then
%do;
%put WARNING: Export step skipped - no output records.;
%end;
%else
%do;
/*source duplicate html creation*/
ods html file ='/mnt/agrm-rrr/1094_sourceduplicate.html' style=sasweb;
PROC REPORT DATA=sourceduplicate NOWD;
COL CDNUMPOL count;
title "B2W 1094 Source Duplicate";
Define CDNUMPOL / display 'CDNUMPOL';
Define count / display 'count';
RUN;
ods _all_ close;
ods html close;
%end;
%mend Export;
%Export
The Issue arise at %Export Section and its not resolving ..
I'm currently using SAS EG ver 7.12 (7.100.2.3350) (32-bit).
Looking forward your reply folks ,..
Thanks in Advance ,
Srini.
When you define dsempty in the first macro, it will be stored in the local symbol table of that macro, and not be available anywhere else.
Use the %global statement to put it in the global symbol table.
When you define dsempty in the first macro, it will be stored in the local symbol table of that macro, and not be available anywhere else.
Use the %global statement to put it in the global symbol table.
Thank you so much .
This solution resolved all of existing issues . Thanks a ton
Have a look at sashelp.vtable, the dataset contains various information about datasets available in the active sas session. The following code sets dsemtpy to 1 if the dataset is empty.
proc sql noprint;
select (nobs=0)
into :dsempty trimmed
from sashelp.vtable
where libname = 'SASHELP' and MemName = 'CLASS'
;
quit;
You can simplfy that to:
data _null_; set sashelp.vtable (where=(libname="<your lib>" and memname="<your dataset>")); if nobs=0 then call execute('%put "No obs found";'); else call execute(' ods html file ="/mnt/agrm-rrr/1094_sourceduplicate.html" style=sasweb; proc report data=sourceduplicate nowd; col cdnumpol count; title "B2W 1094 Source Duplicate"; define cdnumpol / display "CDNUMPOL"; define count / display "count"; run; ods html close;'); run;
Or if you prefer to have the report in a macro then just:
data _null_; set sashelp.vtable (where=(libname="<your lib>" and memname="<your dataset>")); call execute(ifc(nobs=0,'%put "No obs found";','%PrintFile;')); run;
Assuming report macro is called PrintFile.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.