DATA Step, Macro, Functions and more

Checking Authentication in SAS

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

Checking Authentication in SAS

Hi,

 

I am authenticating to the UNIX server using the below statements:-

 

proc printto log='C:\Temp\sastest.log' new;
run;
%let remote=lwstv21.__8015; signon remote=&remote cscript='C:\Script\tcpunix93.scr';
data _null_;
time_slept=sleep(20,1); 
tday=today();
current=time();
put 'Execution time : ' current=time. tday date9. ;
run;
signoff;
proc printto;
run;

My userid and password details are already in the tcpunix93.scr file and this script has been automated. 

But I need to make some changes in the code such that if the signon fails it retries signing on 2 more times . I dont want to read the log file everytime since it will bring much overhead to the code. Please suggest me a way to achieve this requirement.Thanks!


Accepted Solutions
Solution
‎04-19-2016 06:32 AM
Super User
Posts: 3,105

Re: Checking Authentication in SAS

An alternative to @KurtBremser's approach could be using macro and using the RLINK function (untested):

 

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 0;
%let I = 0;
%do %until(&I = &repeat or &rc ne 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr';

data _null_;
  remote_session = optgetc(“&remote”);
  Msg = sysmsg();
  put msg =  remote_session =;
  rc=rlink(remote_session);
  if rc = 0 then put 'No link exists.';
  else put 'A link exists.';
  call symputx(‘rc’, put(rc,2.));
run;
%end;
%mend repeat_signon;

%repeat_signon (remote =%str(lwstv21.__8015));

 

View solution in original post


All Replies
Super User
Posts: 6,936

Re: Checking Authentication in SAS

The best place to do this is the .scr file that controls the logon process (C:\Script\tcpunix93.scr in your case). The syntax for this file is described in the SAS/CONNECT documentation.

 

You will have to manually replay the logon process with telnet so you can see the responses you get from the remote server; you can then code corresponding reactions into the .scr file.

I did that to catch the "password expired" message delivered by AIX and consequently prompt the user for a new password.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎04-19-2016 06:32 AM
Super User
Posts: 3,105

Re: Checking Authentication in SAS

An alternative to @KurtBremser's approach could be using macro and using the RLINK function (untested):

 

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 0;
%let I = 0;
%do %until(&I = &repeat or &rc ne 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr';

data _null_;
  remote_session = optgetc(“&remote”);
  Msg = sysmsg();
  put msg =  remote_session =;
  rc=rlink(remote_session);
  if rc = 0 then put 'No link exists.';
  else put 'A link exists.';
  call symputx(‘rc’, put(rc,2.));
run;
%end;
%mend repeat_signon;

%repeat_signon (remote =%str(lwstv21.__8015));

 

Contributor
Posts: 65

Re: Checking Authentication in SAS

Hi @SASKiwi,

 

The code is giving below error:-

 

68
ERROR 68-185: The function OPTGETC is unknown, or cannot be accessed.

2883 Msg = sysmsg();
2884 put msg = remote_session =;
2885 rc= rlink(remote_session);
-----
68
ERROR 68-185: The function RLINK is unknown, or cannot be accessed.

2886 if rc = 0 then put 'No link exists.';
2887 else put 'A link exists.';
2888 call symputx('rc', put(rc,2.));
2889 run;

 

Super User
Posts: 3,105

Re: Checking Authentication in SAS

[ Edited ]

Sorry, most SCL functions work in the DATA step but obviously not that one. Perhaps try @Bruno_SAS's suggestion in the same macro:

 

%macro repeat_signon ( remote = &remote
                      ,repeat = 3);
%let rc = 99;
%let I = 0;
%do %until(&I = &repeat or &rc = 0);
%let I = %eval(&I+1);
signon remote=&remote cscript='C:\Script\tcpunix93.scr' CMACVAR = signonrc;
%let rc = &signonrc;
data _null_; remote_session = optgetc(“&remote”); Msg = sysmsg(); put msg = remote_session =; if symget('rc') = 0 then put 'A link exists.'; else put 'A link does not exist.'; run; %end;
%mend repeat_signon; %repeat_signon (remote =%str(lwstv21.__8015));

 

Super User
Posts: 6,936

Re: Checking Authentication in SAS

The rlink() function is only present in SCL, so it won't be of much help outside a DMS SAS. An one would need to have SAS/AF licensed to build a SCL program.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 65

Re: Checking Authentication in SAS

Thanks @SASKiwi, you are a saviour.
SAS Super FREQ
Posts: 683

Re: Checking Authentication in SAS

Hi

 

Check the doc for SIGNON Statement and Command. The SIGNON statement provides the CMACVAR option to name a macro variable that will tell you the follwoing:

 

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.
 
Bruno
Contributor
Posts: 65

Re: Checking Authentication in SAS

Thanks @Bruno_SAS

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 335 views
  • 3 likes
  • 4 in conversation