BookmarkSubscribeRSS Feed
Markus91
New User | Level 1

Here is the issue;

 

At work, due to some changes in IT rules, colleagues have differently mapped online folders. This is an issue with shared projects that use those folders as libraries, so I am trying to define this dynamically. The idea is that when you run the project, you get a prompt for which user is running the query and then assign correct path to the program.

 

But the issue is since there are multiple folders that I need to use with different paths. I was thinking of setting a dummy variable and then assign the actual path strings based on an if/then statement. What I cannot find is how to properly assign value to a macro variable with an if-then.

1 REPLY 1
Tom
Super User Tom
Super User

Are you asking how to set the value of a macro variable?  You can use the %LET macro statement.

%let mvar=new value;

Or you could use the CALL SYMPUTX() statement in a data step.

data _null_;
  call symputx('mvar','new value');
run;

To do it conditionally you could use conditional macro code:

%if &username=FRED %then %do;
  %let mvar=new value;
%end;

Or conditional data step code:

data _null_;
  if "&username"="FRED" then do;
    call symputx('mvar','new value');
  end;
run;

But for something so complex you might want to make a dataset that contains the mapping

data mapping;
  infile datalines dsd truncover ;
  input username :$32. value :$200.;
datalines;
FRED,new value
JOE,old value
;

and then use that. Either with a data step:

data _null_;
  set mapping;
  where username="&username";
  call symputx('mvar',value);
run;

Or perhaps PROC SQL

proc sql noprint;
select value into :mvar trimmed
from mapping
where username="&username"
;
quit;

Or you might want to make a FORMAT that maps the username into the right value.

proc format;
value $mapping
  'FRED'='new value'
  'JOE'='old value'
;
run;

Which you could then use with the PUT() or PUTC() function.

%let mvar=%sysfunc(putc(&username,$mapping.));

 

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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
  • 1 reply
  • 81 views
  • 2 likes
  • 2 in conversation