access_granted
access_granted

Reputation: 1907

SAS batch jobs: executing multiple scripts through the same local server connection

When executing a single .sas script, I waste roughly 30 seconds on "establishing connection to a local server" and library loads, which are then followed by a 3-second execution of the sas script itself.

Is it possible to execute multiple sas scripts programmatically (I invoke them via the Windows shell) against the same established connection?

Like a keep-alive TCP channel?

Upvotes: 0

Views: 622

Answers (2)

Vasilij Nevlev
Vasilij Nevlev

Reputation: 1449

Hello access_granted,

You are on the right track. You said in the comments to RawFocus, "it operates like socket server" and in your question "keep alive TCP connection". You can actually archieve thatin SAS with some clever programming.

SAS Socket server: Here’s a SAS server in macro language, looping forever to respond to requests. It’s worth noting while waiting for the next request, the server is in a sleep state, consuming very little resource on its host machine.

/* Port as input parameter */
%let portno= &sysparm;
%* let portno= 001;
%do %while ( 1 );
filename in_msg SOCKET " :&portno"
SERVER;
filename temp_pgm  "%sysfunc(pathname(work))/a-ready.sas" ;
data _null_;
infile in_msg;
 file temp_pgm;
 input ;
 put _infile_;
run;
filename in_msg;
/* Before execution, server can choose to
parse it first */
%inc temp_pgm;
run;
filename temp_pgm;
%end;

This client is supplied with a SAS server’s IP address, port number to call on, and the program file for the server to execute. It is able to send one request to a known available SAS server. Also note the client is responsible for directing the server on which port to send back the results (if required).

%let host= IP-address-for-server-machine;
%let portno= 001;
filename to_servr SOCKET “ &host:&portno” ;
filename input ‘SAS-program-to-be-run-onserver.sas’;
/* Simple scheme to come up with a different port
number to accept response from the server */
%let ret_port= %eval( &portno + 1 );
data _null_;
 file to_servr;
infile input end= EOF;
if _n_ = 1 then do;
/* Required info for the server to return results
back to this client */
 put ‘%let ret_port= ’ “ &ret_port;” ;
 put ‘%let client= IP-address-for-clientmachine;’;
end;
input ;
 put _infile_;
run;
filename input;
filename to_servr;
/* Receiving socket for the results */
filename back_rst SOCKET “ :&ret_port” SERVER;
data null_;
infile back_rst;
 file print;
 input ;
 put _infile_;
run;
filename back_rst;

Source: http://www2.sas.com/proceedings/sugi24/Coders/p083-24.pdf

By the way, you could also consider reconfiguring the SAS server if possible. 30 seconds to start a session is a bit long, especially for the batch session.

Upvotes: 1

Allan Bowe
Allan Bowe

Reputation: 12691

If you're happy for them to run consecutively in the same sas session, you could just create a sas script to execute the other scripts..

options source2; /* puts the contents of the sas files below in the log */
%inc "C:\MyLoc\script1.sas";
%inc "C:\MyLoc\script2.sas";
%inc "C:\MyLoc\script3.sas";

etc.

The drawback with this approach is that your programs will have to be deal appropriately with any remaining work tables / macros / macro variables etc from the previous runs (they won't have clean sessions).

Upvotes: 0

Related Questions