BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
srinidelite
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
Kurt_Bremser
Super User

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.

srinidelite
Obsidian | Level 7

Thank you so much .

 

This solution resolved all of existing issues . Thanks a ton

andreas_lds
Jade | Level 19

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 6885 views
  • 0 likes
  • 4 in conversation