BookmarkSubscribeRSS Feed
deleted_user
Not applicable
All:

I'm sure others in this forum have already successfully dealt with this issue. What is the best/proper way to conditionally terminate a SP and deliver a message to the user ?

The sample code below does terminate the SP based on a query not returning any rows, but we still receive a stored process message about abnormal termination after the message from the program itself.

To get around this, we "eliminated" the SP error message by "cheating" we changed background color to black.

There has to be a better, more graceful way to do condition/exception handling in stored processes.

Thank You.

-Gerry

Gerard T. Pauline
Mgr, Internet/DB Applications
Computer Systems, DoIT
Pace University

========================================================

%Macro ROWS (DS) ;

%Global DSID NLOBSF RC ID ;

%Let DSID = %Sysfunc(Open(&DS));

%If (&DSID) %Then
%Do ;
%Let ROWS = %Sysfunc(Attrn(&DSID, NLOBSF)) ;
%Let RC = %Sysfunc(Close(&DSID)) ;
%End ;

%If (&ROWS = 0) %Then
%Do ;
Data _NULL_ ;
File _WEBOUT ;
Put '' /
'No Data Found !' / <br> '

' / ;
Put '

' /
'' /
'' /
'' /
'
' /
'

There was no data found that satisfied the search ' /
'conditions specified !

' / ;
Put '

' / ;

Call Execute ('EndSAS ;') ;
Call Execute ('%Str(;) ;') ;
Run ;
%End ;
%Else
%Do ;
Data _NULL_ ;
File _WEBOUT ;
Put '' /
'Data Found !

' / ;
Put '

' /
'' /
'' /
'' /
'

Data was found for this query -- ' /
'YIPPEEEE !

' / ;
Put '

' / ;
Call Execute ('%Str(;) ;') ;
Run ;
%End ;

/*

%If (&ROWS = 0) %Then
%Do ;
Data _NULL_ ;
PutLog 'There are no rows in the table !' ;
Call Execute ('EndSAS ;') ;
Call Execute ('%Str(;) ;') ;
Run ;
%End ;
%Else
%Do ;
Data _NULL_ ;
PutLog "There are &ROWS rows in the table" ;
Call Execute ('%Str(;) ;') ;
Run ;
%End ;
*/

%Mend ROWS ;

Proc SQL ;
Create Table IsErika As
Select *
From SATURN.SPRIDEN
Where SPRIDEN_PIDM = &ID ;
Quit ;

%Rows (IsErika)

Data _NULL_ ;
File _WEBOUT ;
Put '' /
'Data Found !

' / ;
Put '

' /
'' /
'' /
'' /
'

Processing continues-------------' /
'YIPPEEEE !

' / ;
Put '

' / ;
Call Execute ('%Str(;) ;') ;
Run ;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 0 replies
  • 911 views
  • 0 likes
  • 1 in conversation