BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Seer
Calcite | Level 5

I need to identify the user name of the current user from within a Stored Process.  Is there a way of doing this?

1 ACCEPTED SOLUTION

Accepted Solutions
Doc_Duke
Rhodochrosite | Level 12

Is &sysuserid what you are looking for?

View solution in original post

3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12

Is &sysuserid what you are looking for?

Seer
Calcite | Level 5

Thanks great, thanks.

PaulHomes
Rhodochrosite | Level 12

Hi Seer,

There are a number of macro variables you can choose from to best suit your needs, but the values they have will depend on the way in which the stored process is configured, the configuration of the server it will run on, and the person who has logged in to run it.  Generally speaking in a stored process you are probably interested in &_METAUSER or &_METAPERSON which will resolve to the userid and name of the person who logged in to run the stored process.  On the other hand &SYSUSERID will be the userid for the SAS process owner which may or not be the person who is running the stored process.  To give you some examples, I have the following stored process code which will show me the various identity values:

data test;
sysuserid="&sysuserid";
metauser="&_metauser";
metaperson="&_metaperson";
run;

proc print;
run;

If I create a stored process with this code and configure it to I run on my "SASApp - Logical Stored Process Server" then I get the following output when it is run:

sysuserid   metauser   metaperson
---------------------------------
sassrv      paul       Paul Homes

If I then modify it to run on my "SASApp - Logical Workspace Server" I will get the following output when it is run:

sysuserid   metauser   metaperson
---------------------------------
paul        paul       Paul Homes

Notice that &SYSUSERID is different.  That's because my "SASApp - Logical Workspace Server" is configured to launch and run the underlying SAS process on-demand as the requesting user, but my "SASApp - Logical Stored Process Server" is configured to pre-launch SAS processes with a fixed set of launch credentials (the sassrv account often used to run SAS stored process and pooled workspace servers). This is a common configuration. In some situations it is also possible and/or necessary to configure a standard workspace server to use a specific set of launch credentials too so I wouldn't rely on this behaviour unless you talk to you platform administrator first.

I would suggest that whilst it may be possible to use &SYSUSERID in some situations you might be better of using &_METAUSER or &_METAPERSON if you want the identity of the person who logged in to the SAS platform to run the stored process.  I would only use &SYSUSERID when you want the identity of the account used to run the SAS operating system process regardless of who logged into SAS to run the stored process.

There is more information on the special _METAUSER and _METAPERSON macro variables in the SAS® 9.2 Stored Processes: Developer's Guide under Writing a Stored Process and Using Reserved Macro Variables (http://support.sas.com/documentation/cdl/en/stpug/61271/HTML/default/viewer.htm#a003152603.htm)

Cheers
Paul

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 8159 views
  • 3 likes
  • 3 in conversation