DATA Step, Macro, Functions and more

how to use SYSUSERID as observation.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 16
Accepted Solution

how to use SYSUSERID as observation.

Hello SAS Fellows, I want to create SAS macro's for WINDOWS environment, which can read system user id (SYSUSERID) as observation. %let ID=%sysget(SYSUSERID); %put &ID; but its not working. I found that SYSUSERID is an Read only automatic variable. Can anyone of you please suggest me something. I am planning to develop an startup macro which can read QC or PROD data as per user's wish.


Accepted Solutions
Solution
‎03-17-2014 10:04 AM
Super User
Super User
Posts: 7,039

Re: how to use SYSUSERID as observation.

Sounds like you just are confused about how to reference the value of a macro variable.

If you have a macro variable named SYSUSERID you can reference the value by placing an ampersand in front of the name.

%put User name is &sysuserid ;

If you want to use the value in a data step then treat it the same as any other text literal, except make sure to use double quotes instead of single quotes. Macro expressions are not resolved inside of single quotes.

data log ;

  userid = "&sysuserid";

run;

View solution in original post


All Replies
Super User
Posts: 7,762

Re: how to use SYSUSERID as observation.

Do you want to write the sysuserid into a data set?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,942

Re: how to use SYSUSERID as observation.

Posted in reply to KurtBremser

Hi,

Does %put &SYSUSERID.; not work for you?

In a data set: avariable = "&SYSUSERID.";

Occasional Contributor
Posts: 16

Re: how to use SYSUSERID as observation.

Yes, it does not work in a way i want :-(

Occasional Contributor
Posts: 16

Re: how to use SYSUSERID as observation.

Posted in reply to KurtBremser

Yes, i want to use my user id in some condition like %let ID=%sysget(&sysuserid); %put &ID; %if &ID = xxxxx %then %do; libname PROD ""; %end; %else %do; libname QC""; %end;

Valued Guide
Posts: 2,177

Re: how to use SYSUSERID as observation.

Looks like you seek a solution that makes user-specific library alllocations.

My recommendation would be to prepare a small program for each user, containing the libname statements for them and invoke those in a way similar to:

%INCLUDE "pathToSharedFolder/Libs_&sysuserid..sas" ;

With this approach you need no macro programming.

You are using &SYSUSERID to select the libname code relevant to each user.

Good luck

peterC

Trusted Advisor
Posts: 3,212

Re: how to use SYSUSERID as observation.

The sysuserid is a automatic sas macro-var can be referred to as &sysuserid
You can retrieve windows (dos) environment-setting like: %put %sysget(appdata);

You can refer windows (dos) and sas-config sets in filenname libname like: libname tstme "!homeshare";

The windows (dos) environmentvar is often pointing to your personal share in networkenvironments.

SAS Logging is already containing the involved userid. What is your issue to solve?

Check cyntia-s paper menioned in:  https://communities.sas.com/thread/55205

---->-- ja karman --<-----
Occasional Contributor
Posts: 16

Re: how to use SYSUSERID as observation.

Yes, Correct. I want to call this ID in my program. I am trying with SYSUSERID automatic variable. Is there any other way to refer this in my program.

Super User
Super User
Posts: 7,942

Re: how to use SYSUSERID as observation.

You can refer to it as per any other macro variable:

%if "&SYSUSERID." = "Me" %then %do;

     something

%end;

%else %do;

...

PROC Star
Posts: 1,322

Re: how to use SYSUSERID as observation.

Hi,

Suggest you post the code of the macro you are trying to develop, and also the log from running the macro.  May also help people help you if you add

  Options Symbogen;

Frequent Contributor
Posts: 106

Re: how to use SYSUSERID as observation.

%let id=&sysuserid;

%put &id;

Solution
‎03-17-2014 10:04 AM
Super User
Super User
Posts: 7,039

Re: how to use SYSUSERID as observation.

Sounds like you just are confused about how to reference the value of a macro variable.

If you have a macro variable named SYSUSERID you can reference the value by placing an ampersand in front of the name.

%put User name is &sysuserid ;

If you want to use the value in a data step then treat it the same as any other text literal, except make sure to use double quotes instead of single quotes. Macro expressions are not resolved inside of single quotes.

data log ;

  userid = "&sysuserid";

run;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 1960 views
  • 0 likes
  • 8 in conversation