BookmarkSubscribeRSS Feed
braam
Quartz | Level 8

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?

 

10 REPLIES 10
mkeintz
PROC Star

Devilishly clever!

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

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

 

 

Tom
Super User Tom
Super User

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

Reeza
Super User

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.


 

 

Tom
Super User Tom
Super User

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.

Reeza
Super User

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.

Tom
Super User Tom
Super User

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.

Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1061 views
  • 2 likes
  • 5 in conversation