BookmarkSubscribeRSS Feed
barbe1lj
Calcite | Level 5

We have a job that runs every morning at 7:00am. Sometimes we have users in reports that are using the cube that the job runs therefore the job fails.

Any suggestion on how to resolve this issue? Is there a script or rule that can be run to kill all sessions? I know how to do this manually but was wondering if anyone has every created a rule/script to do this?

 

Thank you

Lori

2 REPLIES 2
DavidHD
SAS Employee
Yes this can be done by utilizing the proc olapoperate - see the documentation: https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/olapug/n0rh9rcu3ucqzon1o9cb47zbzytj.htm
AhmedAl_Attar
Rhodochrosite | Level 12

Hi @barbe1lj ,

You cab try the following macro

/**
*************************************************************************
* Lists and Closes All/Cube Specific Active Session on the specified OLAP
* Server.
* <br><br>Usage Example:<br>
*	%olap_closeSessions(p_host=
*	,p_userid=
*	,p_password=
*	,p_port=5451
*	,p_cube=_ALL_);<br>
*
* @param	p_host		SAS OLAP Server Host Name network IP address
* @param	p_userid	Registered SAS Metadata User ID to use when
*						logging into the OLAP Server
* @param	p_password	Registered SAS Metadata Password. Please use
*						Encrypted password.
* @param	p_port		TCP/IP Port used by the SAS OLAP Server Process
*						Default:5451
* @param	p_cube		SAS OLAP Cube Name being used
*
*************************************************************************
*/

%MACRO olap_closeSessions(
	 p_host
	,p_userid=
	,p_password=
	,p_port=5451
	,p_cube=_ALL_
	);

	%local l_closeStmt;

	%let l_closeStmt=;

	/* Assign a Filename and redirect the SAS log to it */
	FILENAME outlog TEMP;

	PROC PRINTTO LOG=outlog NEW; RUN;

	/* Get a list of all Active Sessions on the OLAP Server */
	PROC OLAPOPERATE;
		CONNECT HOST="&p_host" PORT=&p_port USERID="&p_userid"
		PASSWORD="&p_password";

 		%if (%superq(p_cube) = _ALL_) %then
 		%do;
			LIST SESSIONS;
		%end;
		%else
		%do;
			  LIST SESSIONS CUBE="&p_cube";
		%end;
	RUN;

	/* Redirect the log back to the original log file */
	PROC PRINTTO LOG=log; RUN;

	/* Get Active Sessions on the OLAP Server */
	DATA WORK.SESSIONS (KEEP=ID);

		INFILE outlog TRUNCOVER;

		LENGTH text $256 ID $71;
		INPUT text $ &;

	    IF SUBSTR(text,1,10) = "Session ID" THEN
	    DO;
			ID = SCAN(text,3,' ');
			output;
		END;
	RUN;

	PROC SQL NOPRINT;
		SELECT	"CLOSE SESSION '"||STRIP(ID)||"';"
		INTO	:l_closeStmt separated by ' '
		FROM	WORK.SESSIONS ;
	QUIT;

	%put l_closeStmt=%superq(l_closeStmt);
	%put sqlobs=&sqlobs;

	/* Close All Active Sessions on the OLAP Server if there were any */
	%if (&SQLOBS GT 0) %then
	%do;
		PROC OLAPOPERATE;
			CONNECT HOST="&p_host" PORT=&p_port USERID="&p_userid"
			PASSWORD="&p_password";
			&l_closeStmt
		RUN;

		%PUT "NOTE: &SQLOBS SAS OLAP Server sessions were closed.";
	%end;

	PROC DATASETS LIB=work NOLIST; DELETE sessions; RUN; QUIT;
%MEND olap_closeSessions;

You can use the sasadm@saspw user credentials to list and close all active sessions, or a specific session for a specific cube.

Hope this helps,

Ahmed 

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 790 views
  • 0 likes
  • 3 in conversation