BookmarkSubscribeRSS Feed
mariko5797
Pyrite | Level 9

I have a macro that runs fine when I run within SAS. However, when I try to batch the file, I get the error that the dataset does not exist.

proc datasets library= work kill noprint; run; 
/*dm "log; clear; output; clear; odsresults; clear;";*/
******************************************************************************************************;
options ls=max noquotelenmax pagesize=max ps=max missing=. compress= yes minoperator nofmterr; 
ods listing close;
******************************************************************************************************;
%let runmode=%upcase(%scan(&sysprocessmode,2)); %put RunMode=&runmode;
******************************************************************************************************;
%global protdir;
%macro RunMode;
 	%if &runmode=BATCH %then %do; %let protdir=%sysfunc(prxchange(s/(\\SAS\\.+)//i,-1, %sysfunc(getoption(sysin)))); %end;
	%if &runmode=DMS %then %do; %let protdir=%sysfunc(prxchange(s/(\\SAS\\.+)//i, -1, %sysget(sas_execfilepath))); %end;
	%put protdir=&protdir;
%mend RunMode;
%RunMode;

%include 'G:\VID\NOROVIRUS\STAT\16-0092\24_Final Reports\SAS\source\16092_CSR_01_setup.sas';

%macro survdat( dsnout,		/*output dataset*/
				pop,		/*analysis population, subgroup*/
			    param,		/*best-case scenario = 1, worst-case scenario = 2*/
				dur= N,		/*by duration of symptoms = Y*/
			    dsnin= _1	/*input dataset*/
				);
	*ods listing close;
	*ods graphics off;
	proc lifetest data= &dsnin. plots= survival;
	 where &pop. = 'Y' and paramn = &param.;
	 time aval*cnsr(1);		/*recovered: CNSR = 0*/
	%if &dur= N %then %do;
	 strata trta;
	%end;
	%if &dur= Y %then %do;
	 strata trtan dursymn;
	%end;
	 *format dursymn sym.;
	 ods output SurvivalPlot= _survdat&dsnout.;
	run;

	proc sql;
	%if &dur= N %then %do;
	 create table N as
	 	select trta, count(distinct usubjid) as n
			from &dsnin.
			where &pop. = 'Y' and paramn = &param.
			group by trta; 
	%end;
	%if &dur= Y %then %do;
	 create table N as
	 	select trta, dursymn, count(distinct usubjid) as n
			from &dsnin.
			where &pop. = 'Y' and paramn = &param.
			group by trta, dursymn;
	%end;
	quit;

	data n;
	 set n;
	 	if dursymn = 1 then label_ = catx(', ', trta, 'Acute');
		if dursymn = 2 then label_ = catx(', ', trta, 'Chronic');
		if missing(dursymn) then label_ = trta;
	run;
%mend survdat;
%survdat(dsnout= 3, pop= mittfl, param= 1);
/*In batch file "ERROR: File WORK._SURVDAT3.DATA does not exist."*/
/*No error when ran directly in SAS.*/
3 REPLIES 3
Tom
Super User Tom
Super User

Since that dataset is the one generated by the ODS OUTPUT statement then I suspect that the actual issue is in the PROC LIFETEST step BEFORE then one that is complaining. 

 

Reading the SAS log should help you see why the dataset was not created.

 

If you do not have the MPRINT option turned on then that can also help make the log cleared by showing what code the macro is actually trying to run.

mariko5797
Pyrite | Level 9
Checked the log. Seems like it wasn't printing the plot at all so I added ODS GRAPHICS ON, and seemed to fix the issue. Thank you!
Quentin
Super User

I'd suggest you turn on OPTIONS MPRINT and run the program as a batch job, then look at the the log from the PROC LIFETEST.  The log will show you whether _survdata3 is created.  But I don't see anywhere in the macro which would generate that error message.  Any chance it's coming from the %INCLUDE file?  Maybe turn on OPTIONS SOURCE2 as well, and then post the full log.  That should be enough for people to help you debug it.

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 695 views
  • 3 likes
  • 3 in conversation