Hi,
How many ways to create a Macro's ?
I Know couple of it like....
%Macro,
% Let
% Local
% Global
Call symput (Data setp)
Into clause (sql)
% Do
is there any other ways ?
Thanks,
Suresh
are macro's and macro variables the same?
Nope !
%let var1=abcde;
Is &var1 a macro or macro variable?
Most of those create macro variables. Only %macro ... %mend can create an actual SAS macro.
There are procedure that will set macro variable values (and create the macro variable if they have to).
PROC SQL
PROC REPORT
Some statements such as
LIBNAME
FILENAME
might also set macro variable values.
Tom: Not quite true! There is also the old style macro! E.g.;
macro print means%
proc print data=sashelp.class;
var height;
run;
%deact print;
proc print data=sashelp.class;
var height;
run;
which will produce:
The MEANS Procedure
Analysis Variable : Height
N Mean Std Dev Minimum Maximum
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
19 62.3368421 5.1270752 51.3000000 72.0000000
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
and then:
Obs Height
1 69.0
2 56.5
3 65.3
4 62.8
5 63.5
6 57.3
7 59.8
8 62.5
9 62.5
10 59.0
11 51.3
12 64.3
13 56.3
14 66.5
15 72.0
16 64.8
17 67.0
18 57.5
19 66.5
Hi:
As you can see from the various responses, using the term "macro" leaves the term open to interpretation and confusion. There are MACRO PROGRAM definitions, which usually are created by using %MACRO and %MEND -- I would say this is the primary method (or using Art's technique for "old style" macro programs).
Then, there are MACRO VARIABLE definitions. Some methods to create MACRO VARIABLES are explicit, such as INTO, %LET or CALL SYMPUT, however, some methods of creating MACRO VARIABLES are implicit, such as the fact that the index variable for a macro language %DO loop will become a usable macro variable.
Personally, I find the macro language section of the documentation to be quite thorough and comprehensive in the discussion of the difference between macro variables and macro programs. I'd suggest that you start there to answer your question.
cynthia
Cynthia (and everyone), I wasn't suggesting that anyone use "old style" macros, I was just making sure that it got added to Tom's list of "possible ways" to create a macro program. I have only seen one case where an "old style" macro turned out to be the only solution to a problem and that was to substitute text in order to override a particular setting in one proc.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.