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 = ¶m.;
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 = ¶m.
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 = ¶m.
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.*/
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.
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.