Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mf_getuser.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns a userid according to session context
4 @details In a workspace session, a user is generally represented by <code>
5 &sysuserid</code> or <code>SYS_COMPUTE_SESSION_OWNER</code> if it exists.
6 In a Stored Process session, <code>&sysuserid</code>
7 resolves to a system account (default=sassrv) and instead there are several
8 metadata username variables to choose from (_metauser, _metaperson
9 ,_username, _secureusername). The OS account is represented by
10 <code> _secureusername</code> whilst the metadata account is under <code>
11 _metaperson</code>.
12
13 %let user= %mf_getUser();
14 %put &user;
15
16 @param type - do not use, may be deprecated in a future release
17
18 @return SYSUSERID (if workspace server)
19 @return _METAPERSON (if stored process server)
20 @return SYS_COMPUTE_SESSION_OWNER (if Viya compute session)
21
22 @version 9.2
23 @author Allan Bowe
24**/
25
26%macro mf_getuser(type=META
27)/*/STORE SOURCE*/;
28 %local user metavar;
29 %if &type=OS %then %let metavar=_secureusername;
30 %else %let metavar=_metaperson;
31
32 %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %let user=&SYS_COMPUTE_SESSION_OWNER;
33 %else %if %symexist(&metavar) %then %do;
34 %if %length(&&&metavar)=0 %then %let user=&sysuserid;
35 /* sometimes SAS will add @domain extension - remove for consistency */
36 %else %let user=%scan(&&&metavar,1,@);
37 %end;
38 %else %let user=&sysuserid;
39
40 %quote(&user)
41
42%mend mf_getuser;