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;

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 8337 views
  • 1 like
  • 8 in conversation