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 is hosting free webinars!
Next up: Rick Wicklin presents Ten Tips for Effective Statistical Graphics (with SAS code) on Wednesday March 26.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 879 views
  • 3 likes
  • 3 in conversation