I am trying to create a job in DI Studio that runs an OS command via the X statement.
For troubleshooting purposes, I need access to the return value from the OS, or the output from the execution, or something that would indicate if it is failing and why.
For simplicity's sake, suppose I had the following code (in the 'pre-code') tab.
x echo $(date) >>RunLog.txt ;
and there was a permissions issue with the output file.
How would I obtain error information from the 'x' command? Or hopefully anything that would have gone to the console or error device.
I realize that control is passing temporarily out of SAS's control, so maybe nothing is possible, but I figured it's worth asking about.
Also, the command may need to have quotes around it, but in either case, the job runs successfully (I.E. no error from DI Studio's point of view), but the command was never executed.
I'm on Studio V4.902
Thanks in advance.
I never use the X command in production SAS code.
Use a data step with a PIPE.
data _null_;
infile "x echo $(date) >>RunLog.txt" pipe;
input;
put _infile_;
run;
Tom,
Thank you for the reply. As it turns out, because I was unaware that SAS Studio is a different product than SAS DI Studio, I have posted to the wrong forum, but your answer is probably just as applicable for DI Studio. If you would not use the X command in prod, then perhaps it's a rule I would want to follow as well, so can you let me know why you choose not to use it?
In addition to infile pipe, use
2>&1
at the end of the command string to redirect stderr to stdout, so that all messages/responses end up in the SAS log.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.