I am working in SAS EG windowing environment with some large macros which have conditional abort statments.
while running code if it encounters error, all datasets are deleted and log is also cleared. is there any way to keep the datasets and log errors so that I can see what is happening and debug ?
@chetan3125 wrote:
Thanks for your answer.
Some progress. Can see the log now but datasets are still cleared.For ex. Can't see datasets if I run following code.
options syntaxcheck ; data c; x=1 ; run; data d; set c ; if x =1 then abort; ; run;
Some options: Do not write to the Work library. I doubt that anything written to a permanent library is deleted.
Investigate the USER option for a library. Changes how single name data sets are stored to library specified as User but should not delete any. However, since the library is basically as permanent library you are responsible for cleaning it up as needed.
Unfortunately there is currently no SAS option for this but it has been long-requested item in the SASware ballot. The closest option I can think of is SYNTAXCHECK which will force a SAS session to go into syntax check mode - run the code but not process any data. That way your log and datasets will be retained.
Thanks for your answer.
Some progress. Can see the log now but datasets are still cleared.
For ex. Can't see datasets if I run following code.
options syntaxcheck ;
data c;
x=1 ;
run;
data d;
set c ;
if x =1 then abort; ;
run;
@chetan3125 wrote:
Thanks for your answer.
Some progress. Can see the log now but datasets are still cleared.For ex. Can't see datasets if I run following code.
options syntaxcheck ; data c; x=1 ; run; data d; set c ; if x =1 then abort; ; run;
Some options: Do not write to the Work library. I doubt that anything written to a permanent library is deleted.
Investigate the USER option for a library. Changes how single name data sets are stored to library specified as User but should not delete any. However, since the library is basically as permanent library you are responsible for cleaning it up as needed.
Sorry no data is produced once in syntax check mode, but the log is retained and you can see datasets up to the point the syntax check mode is triggered. That should be good enough for debugging purposes.
Also remove the ABORT as that will override the behaviour of SYNTAXCHECK.
SAS really dropped the ball by deciding to do nothing when this has been requested for many years. See here to vote, and for a dirty workaround.
Do you have access to the code behind these macros? And are the macros compiled using the SASAUTOS path? If so, you could consider:
Since the macro are already compiled before step 3, SASAUTOS will no longer look for the actual code, but use your version. This could allow you to debug the problem.
Sounds like the original code was designed for batch/background execute not interactive (or pseudo interactive of EG) mode.
You might make some progress using new SAS sessions to run the macros. For example you could use SIGNON command of SAS/Connect to open a new session from your program to run the macro. You could setup that session to not clear the WORK directory when it ends, or perhaps use the USER libref (and now USER option) to have it create one level dataset names into a libref other than WORK. Then your main session could look into the files left behind by the aborted run.
Of course building that might take more work than just fixing the original macros to be more interactive friendly.
@chetan3125, not sure how you ended up solving this. Just a thought for a longer term solution hoping you have some ability to influence that.
I am currently working in an environment where we have the following setup:
Of course this requires some initial investment, but once you have it set up, it will make your life easier.
Thanks for your reply.
As these macros are set up by my organization and they are many so there is no way for me to modify.
Currently I am going through tedious task of batch running the code an fix as much as I can and then run again.
I guess the people in my company who developed these macros did not bother about making users life easy.
Behavior like you describe is typical for batch programs. Anytime something unexpected happens, the program needs to fail in a way that the scheduler can recognize, and at best before faulty data causes the program to destroy something (like updating a production table with faulty data). You also want to fail such a program as early as possible, so the error fixing chain goes to work immediately (no one wants a program to run 3 hours, exit with an ERROR code, and having had the ERROR after 5 minutes of runtime),
So the macros MUST be used as documented, and allow no mistakes. I have created several macros for our production batch codes that act like this.
@Kurt_Bremser, I fully agree that you want behavior like this for batch programs. That is, aborting on the first error that you encounter. However, like I explain above the macro does not need to do the abort. It can throw an error and setting the option ERRORABEND on the Production environment would be sufficient to achieve what you want. In my opinion a more flexible approach.
The macro can check for the existence of a typical Enterprise Guide macro variable and change its behavior based on that.
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.