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
SAS Super FREQ
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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 1 reply
  • 596 views
  • 0 likes
  • 2 in conversation