Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mp_stprequests.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Capture session start / finish times and request details
4 @details For details, see
5 https://rawsas.com/event-logging-of-stored-process-server-sessions.
6 Requires a base table in the following structure (name can be changed):
7
8 proc sql;
9 create table &libds(
10 request_dttm num not null format=datetime.
11 ,status_cd char(4) not null
12 ,_metaperson varchar(100) not null
13 ,_program varchar(500)
14 ,sysuserid varchar(50)
15 ,sysjobid varchar(12)
16 ,_sessionid varchar(50)
17 );
18
19 Called via STP init / term events (configurable in SMC) as follows:
20
21 %mp_stprequests(status_cd=INIT, libds=YOURLIB.DATASET )
22
23
24 @param status_cd= Use INIT for INIT and TERM for TERM events
25 @param libds= Location of base table (library.dataset). To minimise risk
26 of table locks, we HIGHLY recommend using a database (NOT a SAS dataset).
27 THE LIBRARY SHOULD BE ASSIGNED ALREADY - eg in autoexec or earlier in the
28 init program proper.
29
30 @version 9.2
31 @author Allan Bowe
32 @source https://github.com/sasjs/core
33
34**/
35
36%macro mp_stprequests(status_cd= /* $4 eg INIT or TERM */
37 ,libds=somelib.stp_requests /* base table location */
38)/*/STORE SOURCE*/;
39
40 /* set nosyntaxcheck so the code runs regardless */
41 %local etls_syntaxcheck;
42 %let etls_syntaxcheck=%sysfunc(getoption(syntaxcheck));
43 options nosyntaxcheck;
44
45 data ;
46 if 0 then set &libds;
47 request_dttm=datetime();
48 status_cd="&status_cd";
49 _METAPERSON="&_metaperson";
50 _PROGRAM="&_program";
51 SYSUSERID="&sysuserid";
52 SYSJOBID="&sysjobid";
53 %if not %symexist(_SESSIONID) %then %do;
54 /* session id is stored in the replay variable but needs to be extracted */
55 _replay=symget('_replay');
56 _replay=subpad(_replay,index(_replay,'_sessionid=')+11,length(_replay));
57 index=index(_replay,'&')-1;
58 if index=-1 then index=length(_replay);
59 _replay=substr(_replay,1,index);
60 _SESSIONID=_replay;
61 drop _replay index;
62 %end;
63 %else %do;
64 /* explicitly created sessions are automatically available */
65 _SESSIONID=symget('_SESSIONID');
66 %end;
67 output;
68 stop;
69 run;
70
71 proc append base=&libds data=&syslast nowarn;run;
72
73 options &etls_syntaxcheck;
74%mend mp_stprequests;