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.
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.
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;
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.
@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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.