I use %rq to stop SAS from running continuously when an error occurs. My master code file includes a couple of %include statements, which means that several SAS code files are involved in one-go.
%macro rq;
; run; quit;
%if &syserr. > 4 %then %do;
%put "syserr= " &syserr.;
%abort cancel;
%end;
%mend rq;
I encountered two annoying issues.
1) When an error occurs (and SAS stops), I don't know in which SAS code file the program stopped. Can I add a couple of lines to let me know the file where the program encountered the error?
2) Even when I know the code where the error happened, I need to look through the code file to get to the exact place of the error code. Is there any tip that can make this process easier?
When encountering a problem, I simply scan the log file for the word ERROR. That lets me locate the cause rather quickly.
Devilishly clever!
@Kurt_Bremser that doesn't apply here because when you use %INCLUDE() the code doesn't go to the log, so even if you get an ERROR message it's useless at that point.
@Reeza wrote:
@Kurt_Bremser that doesn't apply here because when you use %INCLUDE() the code doesn't go to the log, so even if you get an ERROR message it's useless at that point.
That is not true. It only doesn't show the code in the log if you tell it not to display the code in the log.
No code in the log is the default behaviour of %INCLUDE. There's none of the code included in the log which would indicate where it actually happened. And no, saying the error is in the %INCLUDE statement is not enough to answer the OP's question.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK; 68 69 %include '/home/fkhurshed/Demo1/error_test.sas'; ERROR: File SASHELP.CLAS.DATA does not exist.
@Tom wrote:
@Reeza wrote:
@Kurt_Bremser that doesn't apply here because when you use %INCLUDE() the code doesn't go to the log, so even if you get an ERROR message it's useless at that point.
That is not true. It only doesn't show the code in the log if you tell it not to display the code in the log.
But this is only because you didn't set the SOURCE2 option. You can to it with an OPTIONS statement if you don't want to add it to every individual %INCLUDE statement. You can also set the NOSOURCE option and have the code from the main program not displayed in the log.
So I need to explicitly specify to tell it to put the code to the log? If I don't, the default is to not include it? Please explain how I told it not to put it in the log, according to your statement:
That is not true. It only doesn't show the code in the log if you tell it not to display the code in the log.
Run proc options and check. It is your choice what options you set in your command line, config file, autoexec file, program, etc. In addition to SOURCE and SOURCE2 there is MPRINT and MACROGEN. Also MLOGIC and SYMBOLGEN.
When running code with potentially unreliable includes, options source2 has to be set.
Make sure to use SOURCE2 option. Either set it globally or use on the individual %INCLUDE statement.
639 %include text / source2; NOTE: %INCLUDE (level 1) file TEXT is file /Volumes/scratch/SAS_work175900044221/#LN00111. 640 +* inside text file; NOTE: %INCLUDE (level 1) ending.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.