BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
How many types we can pass the macro parameters and any one can send the links for that macros
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi:
I'm not sure I understand the question. SAS Macro programs are basically performing text substitution. So, if you do this:
[pre]
%macro showme(want1=, want2=);
ods listing;
proc print data=sashelp.class;
title "WANT1 = &want1 || WANT2 = &want2";
where name = "&want1" or age = &want2;
run;
%mend showme;
[/pre]

What you are doing is saying that you will pass 2 parameters to this macro program. &WANT1 will be used as a character constant for the WHERE clause selection. &WANT2 will be used as a numeric constant for the WHERE clause. When you pass the parameters in the macro invocation, they are merely text strings...they must be treated appropriately in your program. So, when you do this invocation:
[pre]
%showme(want1=Fred, want2=15);
[/pre]

The macro processor merely does your typing for you, and generates the following resolved code:
[pre]
ods listing;
proc print data=sashelp.class;
title "WANT1 = Fred || WANT2 = 15";
where name = "Fred" or age = 15;
run;
[/pre]
...and then sends -this- resolved code to the compiler to be checked and then executed -- after all the macro variable references have been resolved.

If you want to do arithmetic, you might think you could do this: [pre]
%showme(want1=Xavier, want2=10+3); [/pre]

And, in fact, you would be half right. The WHERE clause could handle getting 10+3 because age=10+3 is valid in a where expression. But, the TITLE statement would show you:
[pre]
WANT1 = Xavier || WANT2 = 10+3
[/pre]

Because when the macro variable reference for &WANT2 resolved, the text string 10+3 is just a bunch of numbers and symbols in the TITLE statement.

So the short answer to your question is that you pass only text strings as parameters to your macro program and your code must treat those text strings appropriately.

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 822 views
  • 0 likes
  • 2 in conversation