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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 0 replies
  • 613 views
  • 0 likes
  • 1 in conversation