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(
27)/*/STORE SOURCE*/;
28 %local user;
29
30 %if %symexist(_sasjs_username) %then %let user=&_sasjs_username;
31 %else %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %do;
32 %let user=&SYS_COMPUTE_SESSION_OWNER;
33 %end;
34 %else %if %symexist(_metaperson) %then %do;
35 %if %length(&_metaperson)=0 %then %let user=&sysuserid;
36 /* sometimes SAS will add @domain extension - remove for consistency */
37 /* but be sure to quote in case of usernames with commas */
38 %else %let user=%unquote(%scan(%quote(&_metaperson),1,@));
39 %end;
40 %else %let user=&sysuserid;
41
42 %quote(&user)
43
44%mend mf_getuser;