Help using Base SAS procedures

macro parameter types

Reply
Regular Contributor
Posts: 229

macro parameter types

How many types we can pass the macro parameters and any one can send the links for that macros
SAS Super FREQ
Posts: 8,743

Re: macro parameter types

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
Ask a Question
Discussion stats
  • 1 reply
  • 94 views
  • 0 likes
  • 2 in conversation