There there a way for one macro parameter to refer to another? To use a really simplistic example, what if I had the following? In the second iteration, the parameters have the same value. Is there a way for the second parameter to refer to back to the first?
options mprint;
%macro vals(a,b);
data _null_;
x=&a;
y=&b;
run;
%mend;
%vals(1,2)
%vals(1,1)
@Batman wrote:
I'm trying to avoid listening the duplicate parameter the second time. It may seem like a dumb request in this case, the actual program I'm working with is a lot more complicated and I just use this one the simplicity of explanation. I'll give you an example that doesn't work, but it did, would solve the problem.
Thanks, I think I understand now. 🙂
Try this:
%global a1;
%macro vals(a,b);
%let a1=&a;
data _null_;
x=&a;
y=&b;
run;
%mend;
%vals(1,2)
%vals(1,&a1)
Although, I get the very strong feeling that if you explained to bigger problem, there might be better ways to do this. Often it is very helpful to hear WHY you need this, rather than just hearing that you do need this.
I guess I don't understand the question.
Can you give an example of what you expect? Can you provide a deeper explanation in words (not in SAS code)?
I'm trying to avoid listening the duplicate parameter the second time. It may seem like a dumb request in this case, the actual program I'm working with is a lot more complicated and I just use this one the simplicity of explanation. I'll give you an example that doesn't work, but it did, would solve the problem.
options mprint;
%macro vals(a,b);
data _null_;
x=&a;
y=&b;
run;
%mend;
%vals(1,2)
%vals(1,&a)
@Batman wrote:
I'm trying to avoid listening the duplicate parameter the second time. It may seem like a dumb request in this case, the actual program I'm working with is a lot more complicated and I just use this one the simplicity of explanation. I'll give you an example that doesn't work, but it did, would solve the problem.
Thanks, I think I understand now. 🙂
Try this:
%global a1;
%macro vals(a,b);
%let a1=&a;
data _null_;
x=&a;
y=&b;
run;
%mend;
%vals(1,2)
%vals(1,&a1)
Although, I get the very strong feeling that if you explained to bigger problem, there might be better ways to do this. Often it is very helpful to hear WHY you need this, rather than just hearing that you do need this.
This seems reasonable.
47 %macro vals(a,b);
48 %put _local_;
49 %if %superq(b) eq %then %let b=&a;
50 %put _local_;
51 %mend;
52 %vals(1,2)
VALS A 1
VALS B 2
VALS A 1
VALS B 2
53 %vals(1)
VALS A 1
VALS B
VALS A 1
VALS B 1
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.