BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
CurtisMackWSIPP
Lapis Lazuli | Level 10

How do you raise a custom error(exception) in DS2. In traditional DATA step you can use a put statement with a string starting with "ERROR:".  This will show as an error highlighted in red in the log. In EG it is also listed in the errors list, making it very obvious that an error was thrown.  In DS2, it doesn't highlight the statement in red and it does not show in the error list. The same thing is true of "NOTE:" and "WARNING:".  I am using the STOP statement which will stop execution, but if you don't carefully look at the log, it looks like a successful execution.

 

Here is some code demonstrating what I am talking about:

 


proc ds2;

  package work.test/overwrite=yes;
    method test();
      put 'ERROR: This is a test error in a called package method';
    end;
  run;

  data _null_ ;
    method init();
      declare package work.test test1;
      test1 = _new_ work.test();
        put 'ERROR: This is a test error in init method';

    end;
    method run();
        put 'ERROR: This is a test error in run method';
        stop;
    end;
  enddata;
run;
quit;

data _null_;
  put "ERROR: This is a test error within a data step that works";
run;

Thanks for taking the time to look at this.

1 ACCEPTED SOLUTION

Accepted Solutions
CurtisMackWSIPP
Lapis Lazuli | Level 10

When I didn't get a reply from this forum, I went ahead and submitted it to SAS tech support.

They confirmed that there is currently no way to do this.  They have entered "a suggestion for R&D to see if they could consider
incorporating this into the DS2 code." and "will continue to monitor it. If it gets incorporated into PROC DS2 code,
I will write a SAS note so our user community knows"

I have added the following comment to the track.

Thank you for submitting the request. The ability to cleanly and effectively handle and escalate error conditions is a fundamental feature of any programing language. DS2 is bringing to SAS the ability to create modular encapsulated code where that feature is even more critical. I would like to clarify that I am not requesting they use the same method for raising errors as in the DATA step. This has always been a hack. I would much rather they incorporate new commands to explicitly raise error conditions with user defined messages.

View solution in original post

2 REPLIES 2
CurtisMackWSIPP
Lapis Lazuli | Level 10

When I didn't get a reply from this forum, I went ahead and submitted it to SAS tech support.

They confirmed that there is currently no way to do this.  They have entered "a suggestion for R&D to see if they could consider
incorporating this into the DS2 code." and "will continue to monitor it. If it gets incorporated into PROC DS2 code,
I will write a SAS note so our user community knows"

I have added the following comment to the track.

Thank you for submitting the request. The ability to cleanly and effectively handle and escalate error conditions is a fundamental feature of any programing language. DS2 is bringing to SAS the ability to create modular encapsulated code where that feature is even more critical. I would like to clarify that I am not requesting they use the same method for raising errors as in the DATA step. This has always been a hack. I would much rather they incorporate new commands to explicitly raise error conditions with user defined messages.

Tom
Super User Tom
Super User

I seem to remember this was raised a few years ago.

 

Note that the COLOR of the text is only something you would worry about in some interactive interface.  The log files generated when you run SAS code does not contain any highlighting.  So whatever tools you are currently using to analyze the your SAS logs to detect errors will treat the lines generated by PROC DS2 and DATA step the same.

 

As to the bigger issue of whether PROC DS2 will introduce methods for trapping (and tripping) errors that is potentially much more useful than what colors you see or don't see on the screen.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 658 views
  • 2 likes
  • 2 in conversation