user3658367
user3658367

Reputation: 641

Use ERROR in if statement of SAS

I just wrote a macro which to sign on to a remote server, of course a simple macro

%macro sign(servername);
%put                                                         ;
%put *********   You are now entering the server   ********* ;
%put *********                                     ********* ;


signon &servername user=_promopt_ password=_prompt_;

%if error %then

%put There is a problem in logging in;

%else 


%put *********                                     ********* ;
%put *********                                     ********* ;
%put *********   You are now ready to use server   ********* ;
%put *********                                     ********* ;
%put *********                                     ********* ;
%mend;

SO here I want to just put something in log saying if it throws an error for whatsoever reason., that may be wrong password or connection or anything, I want to print a statement with the help of %Put but not sure how.

Upvotes: 1

Views: 234

Answers (1)

Tom
Tom

Reputation: 51566

You should be able to use the CMACVAR option on the SIGNON statement.

signon &servername user=_promopt_ password=_prompt_ cmacvar=cerror;
%if &cerror %then

CMACVAR=value

specifies the name of the macro variable in which SAS stores a code indicating the state of the current sign-on. When a SIGNON is executed, SAS checks the state of the sign-on and stores a return code of 0, 1, or 2 in the specified CMACVAR variable.

The return code is generated after SIGNON processing is complete and the name that you specify becomes the default name for the current server session.. The CMACVAR macro variable can then be programmatically queried to learn the processing status of the sign-on (completed, failed, or in progress). See CMACVAR Macro Variable Values in SIGNON for a description of what each return code means.

CMACVAR Macro Variable Values in SIGNON
Value Description
0 The sign-on is complete.
1 The sign-on failed.
2 You have already signed on to the current server session.
3 The sign-on is in progress.

Note: If the SIGNON command or statement fails because of incorrect syntax, the macro variable is not set.

Upvotes: 3

Related Questions