I have a batch file(xyz.bat) which is doing 3 things:
1-Running program.sas in Batch mode
2-Running logcheck.sas macro in Batch mode
3-delete program.log file in Batch mode
Above Batch file(xyz.bat) is generated by Program2.SAS. Rather than running the BATCH file by using double click.
I just want to run it from SAS Program(Program2.SAS) itself.
First option to run batch file from Program2.SAS
options noxwait noxsync;
data _null_;
X 'C:\path\temp-batch.bat';
run;
Second option to run batch file from Program2.SAS
options noxwait noxsync;
data _null_;
X " 'C:\Windows\System32\cmd.exe' 'C:\path\temp-batch.bat' ";
run;
Nothing is working. Please note that there is no syntax error in the program.
Hope you tried renaming the file and executed the code
options noxwait noxsync;
data _null_;
X 'C:\path\temp_batch.bat';
run;
"Nothing is working" tells us exactly this: nothing.
Why do you want to execute a batch-job running sas while you are already in a running sas-session?
Why not just %include the other sas-programs?
XCmd is enabled?
Don't use the x statement, as it does not provide any diagnostic information that can help you in solving issues. Use the filename pipe method to run external commands:
filename oscmd pipe "C:\path\temp-batch.bat 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
Look at your log to see all responses you get back from the operating system.
So, you run the code suggested by @Kurt_Bremser and nothing was written to the sas log? And "program.sas" doesn't write a log, too?
@sumitpratap wrote:
nops. Why don't you create a sample batch and try to run it from SAS program. then tell me if you are able to run.
No problem, works as expected:
NOTE: Writing HTML(EGHTML) Body file: EGHTML
24
25 GOPTIONS ACCESSIBLE;
26 filename oscmd pipe "b:\test.bat 2>&1";
27
28 data _null_;
29 infile oscmd;
30 input;
31
32 put _infile_;
33 run;
NOTE: The infile OSCMD is:
Unnamed Pipe Access Device,
PROCESS=b:\test.bat 2>&1,
RECFM=V,LRECL=32767
SASApp_Dir>echo "Test"
"Test"
NOTE: 3 records were read from the infile OSCMD.
The minimum record length was 0.
The maximum record length was 36.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.00 seconds
First of all, create a sample batch file that creates output (eg echo "Test"), and run that, and see if you get the output in the SAS log of the calling program.
Once that is verified, make sure that your second SAS program is called from the batch file in a way so that it writes a dedicated log with
-logparms "write=immediate"
in order to watch its progress.
If in doubt, post the log from my suggested data _null_ step.
@sumitpratap wrote:
I have a batch file(xyz.bat) which is doing 3 things:
1-Running program.sas in Batch mode
2-Running logcheck.sas macro in Batch mode
3-delete program.log file in Batch mode
Above Batch file(xyz.bat) is generated by Program2.SAS. Rather than running the BATCH file by using double click.
I just want to run it from SAS Program(Program2.SAS) itself.
First option to run batch file from Program2.SAS
options noxwait noxsync;
data _null_;
X 'C:\path\temp-batch.bat';
run;
Second option to run batch file from Program2.SAS
options noxwait noxsync;
data _null_;
X " 'C:\Windows\System32\cmd.exe' 'C:\path\temp-batch.bat' ";
run;
Nothing is working. Please note that there is no syntax error in the program.
If a program file is a SAS program you can reference it with %include. No reason to place into a separate "batch file". You can create the text program inside the program that calls it.
Brief example:
data _null_; file "c:\exampleprog.sas"; put "Proc print data=sashelp.class;run;"; run; %include "c:\exampleprog.sas";
You might be ahead of the game to route the log as needed to a separate or null file instead of worrying about cleaning up the created log. There a fair number of system options as well as Proc Printto to redirect or control what appears in the log. If you are "deleting" the log without looking at it, then options about creating or contents may be in order.
BTW, when something does not work please post the code you submitted and the log to show us what actually happened.
@sumitpratap wrote:
Running Batch file from SAS program is a must. I can't explain the full problem here. But Alternative solution will not work for me. Anyways, thanks for your time.
Still haven't provided any logs or details of what goes wrong.
Where are you writing the batch file? On your computer or the EG Server? Do the paths for all the generated code and the log point to things on your computer or the EG server? Your EG sessions may very well not see the paths if any of them refer to your computer. They may also point to places on the EG server where you do not have read, execute and/or delete permissions if the paths are valid.
Note that there isn't really an EG server. There might be a SAS server that EG is using to run the SAS code it creates.
In your EG session you can pick which server you are using to run your SAS code. If you have SAS installed on the same machine as EG is runnng on then the SAS code might be running on the same machine as EG. But the SAS server could just as likely be using a different operating system than the PC you are using to run EG. It might even be using a different userid than your PC uses to connect to your local network.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.