Hi all,
I just wonder if I use SASpy library submit method to run .sas code in a SAS server, how should I know that the .sas code run successfully or not? Especially in automatic scheduling job using SASpy to run .sas code. Thanks!
Thanks! It is non-grid SAS server running on Windows platform.
1)
Check the LOG file generated by .sas file . In it ,if there are not any ERROR or WARNING message, then .sas is running successfully.
2)
Check OS return code:
[sasuser2@sas1 scripts]$ ls -l total 4 -rwxr-xr-x 1 sasuser2 sasusers 1125 Nov 28 17:10 remote_ifre.sh [sasuser2@sas1 scripts]$ cat remote_ifre.sh #!/bin/bash SERVER1=10.7.70.39 SERVER1_PORT=22 SERVER1_USER=ifre1 SERVER2=10.7.70.40 SERVER2_PORT=22 SERVER2_USER=ifre1 #nc -z -w 2 ${SERVER1} ${SERVER1_PORT} (sleep 1;)|telnet ${SERVER1} ${SERVER1_PORT} 2>&1|grep 'Escape character' > /dev/null 2>&1 if [ $? -eq 0 ];then echo "[+] ${SERVER1} detection successful." ssh ${SERVER1_USER}@${SERVER1} 'sh /data/ifre1/ifre.sh' if [ $? -eq 0 ];then echo "[+] Script exec success on ${SERVER1}." else echo "[+] Script exec failed on ${SERVER1}." fi
Thanks for your comments! I think it's better to search "ERROR" in latest SAS log file. However I don't know whether the WARNING message is really error.
Thanks! I agree with you. If one WARNING message indicates a logic error problem, we can think it's an error. But if that WARNING is an error, why not report it as ERROR directly. There should be some cases of WARNING which are not errors. How do we distinguish them during automatic scheduling jobs?
Thanks! I agree with you. For automatica SAS job scheduling, if there are ERRORs or WARNINGs in the sas log file, it should report the job is failed to notify user something wrong there.
take a look at this part of the doc and see if it answers your question:
https://sassoftware.github.io/saspy/advanced-topics.html#automatic-checking-for-error-in-the-log-and...
Also, you can access the SAS automatic macro variables as needed to check them:
https://sassoftware.github.io/saspy/api.html#saspy.sasbase.SASsession.SYSERR
as well as any macro variable using symget().
Thanks! Use SYSERR macro is helpful if SAS or user defined procedures or steps write return code to syserr. From my understanding, it not as useful as checking ERROR in SAS log file.
Thanks! This enhancement is convenient for us to catch ERROR through SASpy. Only check_error_log method is called to verified. User doesn't need to check log file himself. As the document points out, there is no perfect solution to know whether it's a real problem there. From automatic SAS job scheduling perspective, if we find there is ERROR in log file, no matter it's checked through check_error_log or ourselves, we can just report that scheduling job failed and let user to verify in further steps.
@sastpw wrote:
take a look at this part of the doc and see if it answers your question:
https://sassoftware.github.io/saspy/advanced-topics.html#automatic-checking-for-error-in-the-log-and...
Do you know HOW the saspy code is doing this check? I have seen a lot of lazy log scanners that just search for the letters ERROR in the log and so flag CODE that is there to potentially write an error message when an issue is detected causing many false positives.
Also if you are searching for ERROR: as the note says then there are some error messages that SAS writes where there is other text between the end of ERROR and the colon character.
Yes, in fact, I do know HOW. I wrote SASPy 🙂
And, I've had to enhance how I was doing that a couple of times over the years to account for SAS idiosyncrasies, like having text between the ERROR and the :, and for cases where logging has been enhanced by the user such that the log contains other formatted content, like timestamps and pids and stuff either before or after the SAS log output - so ERROR isn't even in column 1 of the log I get back. Lots of crazy stuff.
Here's the check:
if re.search(r'\nERROR[ \d-]*:', logd):
warnings.warn("Noticed 'ERROR:' in LOG, you ought to take a look and see if there was a problem")
self._sb.check_error_log = True
Unfortunately, SAS was never completely consistent, like a regular programming language where you call a function and check a return code, regarding programmatically being able to asses the results from submitted code. As others have mentioned, sometimes you can see ERROR: in the log and there wasn't really an error that kept things from working. Sometimes something doesn't work and you don't get ERROR. WARNING can't preclude something not working, or prove it did. The system Macros like SYSERR SYSINFO and all the others, aren't 100% reliable. All that.
So, I try my best to provide these things so you can have the best chance of programmatically assessing your code. The best advice may be to only submit 1 SAS step of code at a time and use whichever method (Error check, Macro, ...) that works best for assessing that step, instead of submitting a whole program full of stuff and trying to assess all of it. Note you can also do things like, after a data step, check to see if the table exists and it has the number of rows expected.
SASPy is used in house for testing and that testing is automated and self assessing, using these various means to assess whether the code passed or failed. I wish there was simply one return code you could check for any SAS code you submit, but there isn't.
Tom
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.