BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

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)

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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.

 

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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)?

--
Paige Miller
Batman
Quartz | Level 8

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)

PaigeMiller
Diamond | Level 26

@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.

 

 

--
Paige Miller
data_null__
Jade | Level 19

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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