In my last post I created an encoded password file. This macro utilizes the password to make a connection to a SAS/Connect server.
After your password is read in from the password file, you need to specify the name of the SAS/Connect server and its listening port. Once complete, you specify a few options, all of which are described in the below code. After that, you invoke the SIGNON command. The rest of the code does some fundamental error handling.
It is always a good idea to encapsulate code into a single reusable module for maintainability. In this case that container is a SAS macro. What follows is the entire source code to connect to a SAS/Connect server.
/************************************************************************** * Program: connecttoserver.sas * Author: Tom Bellmer * Created: 20171202 * SAS Version: SAS 9.4 (TS1M3) * OS: Linux * Purpose: Establish SAS/Connect session to 1SG * Usage: %connecttoserver() * Note: Be sure to add SIGNOFF SASGRID ; when finished. **************************************************************************/ %macro connecttoserver() ; %global sasgrid ; /* read in the encoded password */ %inc "%sysget(HOME)/drowssap.dwp" ; /* 7551 is the listening port of the Connect Spawner */ %let sasgrid = yourhostname 7551 ; options comamid = tcp /* Communications access method */ remote = sasgrid /* Points to &sasgrid, no & required */ netencryptalgorithm = aes /* value of remote server */ noconnectmetaconnection /* Bypass metadata authentication */ ; signon sasgrid cmacvar = signonstatus /* macro var to validate connection */ connectstatus = no /* No Status window */ noscript /* Not using script, this is faster */ signonwait = yes /* wait for connection */ username = "&sysuserid." password = "&password." ; %if &signonstatus. = 0 %then %do ; %put %str(N)OTE: Signon to SASGRID on host &syshostname. is successful. ; %end ; %else %if &signonstatus. = 2 %then %do ; %put %str(N)OTE: Connected to existing session on host &syshostname.. ; %end ; %else %do ; %put %str(E)RROR: Signon to SASGRID failed, (return code: &signonstatus.) ; %abort cancel ; %end ; %mend ; /*EOF: connecttoserver.sas */
No comments:
Post a Comment