Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
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 @return SYSUSERID (if workspace server)
17 @return _METAPERSON (if stored process server)
18 @return SYS_COMPUTE_SESSION_OWNER (if Viya compute session)
19
20 @version 9.2
21 @author Allan Bowe
22**/
23
24%macro mf_getuser(
25)/*/STORE SOURCE*/;
26 %local user;
27
28 %if %symexist(_sasjs_username) %then %let user=&_sasjs_username;
29 %else %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %do;
30 %let user=&SYS_COMPUTE_SESSION_OWNER;
31 %end;
32 %else %if %symexist(_metaperson) %then %do;
33 %if %length(&_metaperson)=0 %then %let user=&sysuserid;
34 /* sometimes SAS will add @domain extension - remove for consistency */
35 /* but be sure to quote in case of usernames with commas */
36 %else %let user=%unquote(%scan(%quote(&_metaperson),1,@));
37 %end;
38 %else %let user=&sysuserid;
39
40 %quote(&user)
41
42%mend mf_getuser;