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

If the macro variable DSN resolves to 'FACTOR' then I want the macro variable NAME to resolve it as 'AMM' otherwise I want to resolve it how it resolves earlier.

 

Macro variable NAME is being resolved based on some logic and I want to overwrite that logic only if the value of other macro variable DSN resolves to 'FACTOR'.

 

Appericiate if someone of you shed some light on this.

1 ACCEPTED SOLUTION

Accepted Solutions
Amir
PROC Star

Not sure if you're using macro code or data step code.

 

If you're using macro code then you could try something like the following then check the log for the results:

 

/* macro method */
%macro set_name;
   %if &dsn eq FACTOR %then
      %let name = AMM;
%mend set_name;

%let dsn  = ABC;
%let name = XYZ;
%set_name;
%put name = &name;

%let dsn  = FACTOR;
%set_name;
%put name = &name;

If you're using data step code then the following should also work:

 

/* data step method */
data _null_;
   if "&dsn" eq 'FACTOR' then
      call symputx('name','AMM');
run;

 

Kind regards,

Amir.

View solution in original post

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

Hi @David_Billa 

 

I have tried this. Let me know!

Best,

 

 

options mlogic;
/* Initialization */ %let NAME = initial_value; %let DSN = FACTOR; %put &NAME &DSN; /* Conditional execution*/ %macro mv(); %if "&DSN" = "FACTOR" %then %do; data _null_; call symputx("NAME","AMM"); run; %end; %mend; %mv; /* Result */ %put &NAME &DSN;
Amir
PROC Star

Not sure if you're using macro code or data step code.

 

If you're using macro code then you could try something like the following then check the log for the results:

 

/* macro method */
%macro set_name;
   %if &dsn eq FACTOR %then
      %let name = AMM;
%mend set_name;

%let dsn  = ABC;
%let name = XYZ;
%set_name;
%put name = &name;

%let dsn  = FACTOR;
%set_name;
%put name = &name;

If you're using data step code then the following should also work:

 

/* data step method */
data _null_;
   if "&dsn" eq 'FACTOR' then
      call symputx('name','AMM');
run;

 

Kind regards,

Amir.

PaigeMiller
Diamond | Level 26

@David_Billa wrote:

If the macro variable DSN resolves to 'FACTOR' then I want the macro variable NAME to resolve it as 'AMM' otherwise I want to resolve it how it resolves earlier.

 

Macro variable NAME is being resolved based on some logic and I want to overwrite that logic only if the value of other macro variable DSN resolves to 'FACTOR'.

 

Appericiate if someone of you shed some light on this.


%if &dsn=FACTOR %then %let name=ANN;

Please note that macro variable values do not have quotes around them, and are case sensitive.

--
Paige Miller

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
  • 3 replies
  • 4184 views
  • 2 likes
  • 4 in conversation