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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

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

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

P_Sharma
Calcite | Level 5

Yes, it does not work in a way i want 😞

P_Sharma
Calcite | Level 5

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;

Peter_C
Rhodochrosite | Level 12

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

jakarman
Barite | Level 11

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 --<-----
P_Sharma
Calcite | Level 5

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

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

     something

%end;

%else %do;

...

Quentin
Super User

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;

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
pradeepalankar
Obsidian | Level 7

%let id=&sysuserid;

%put &id;

Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 11 replies
  • 9356 views
  • 1 like
  • 8 in conversation