BookmarkSubscribeRSS Feed
sumitpratap
Obsidian | Level 7

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.

16 REPLIES 16
Jagadishkatam
Amethyst | Level 16

Hope you tried renaming the file and executed the code

 

options noxwait noxsync;

data _null_;
X 'C:\path\temp_batch.bat';
run;
Thanks,
Jag
sumitpratap
Obsidian | Level 7
This will not work. Already tried.
andreas_lds
Jade | Level 19

"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?

sumitpratap
Obsidian | Level 7

"Nothing is working" tells us exactly this: nothing.==> I am not able to run bacth file from SAS program.

XCMD is enabled. no issue with that. Other commands like Copy is working fine.

Running is batch file from SAS program is something different that running any DOS command using X statement.
Kurt_Bremser
Super User

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.

 

sumitpratap
Obsidian | Level 7
Not helping. Note that Batch file don't have any issue.
Suggested program doesn't write anything to log and goes into running mode for too long(I have waited for 15-20 mins).

Problem is, SAS program is not able to run batch file.
andreas_lds
Jade | Level 19

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
Obsidian | Level 7
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.
andreas_lds
Jade | Level 19

@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
Kurt_Bremser
Super User

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.

ballardw
Super User

@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
Obsidian | Level 7
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.
ballardw
Super User

@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.

Tom
Super User Tom
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 16 replies
  • 12243 views
  • 4 likes
  • 7 in conversation