The document provides an introduction to macros in SAS, including how to create macro variables, the macro processing cycle, and storing and reusing macros. It discusses four main topics: an introduction to macros, methods for creating macro variables, the macro processing cycle including compiling and quoting, and techniques for storing and reusing macros such as autocall libraries. The document also includes examples of replacing text with macro variables.
8. 2. Where does SAS store macro variables?
PDV, program data vector
Second memory area
9.
10.
11.
12.
13.
14. 3. What is the title on the report in the following?
%let dwarfs = 7;
proc print data = awards;
title 'There are were &dwarfs small statues awarded in
1939';
run;
A. There are were &dwarfs small statues awarded in 1939
B. There are were 7 small statues awarded in 1939
15. 3. What is the title on the report in the following?
%let dwarfs = 7;
proc print data = awards;
title 'There are were &dwarfs small statues awarded in
1939';
run;
A. There are were &dwarfs small statues awarded in 1939
B. There are were 7 small statues awarded in 1939
The macro facility does not "peak inside" code with single
quotes to resolve macro variables.
16. 4. How to replace with macro variables?
%let year = 2007;
%let month = MAR;
%let type = revenue;
%let libinfo = company;
Target:
Libname company 'C:m data''
proc print data = company.MAR2007;
var revenuecanada revenueus;
run;
17. 4. How to replace with macro variables?
%let year = 2007; Whenever SAS encounters a
%let month = MAR; period after a macro variable
%let type = revenue; reference, the period is
treated as a way to end the
%let libinfo = company;
macro variable and then the
period is thrown away.
Answer:
Libname &libinfo 'C:m data''
proc print data = &libinfo..&month&year;
var &type.canada &type.us;
run;
18. 5. What is the ???? in the following?
%let mouse1 = Mickey;
%let mouse2 = Minnie;
%let mouse3 = Miss Bianca;
%let num=2;
%let type = mouse;
proc print data = work.all_movies;
where star = "????";
title "???? is my favorite character";
run;
19. 5. What is the ???? in the following?
%let mouse1 = Mickey;
&&mouse&num
%let mouse2 = Minnie;
%let mouse3 = Miss Bianca;
%let num=2; &mouse2
%let type = mouse;
proc print data = work.all_movies; Minnie
where star = "&&mouse&num";
title "&&mouse&num is my favorite character";
run;
20. 6. How to assign singleq with O'neill ?
We have
%let singleq = O'neill;
%put &singleq; Is this the result?
Warning
21. 6. How to assign singleq with O'neill ?
We have
%let singleq = %str(O%'neill);
%put &singleq;
Umatched quotation marks('): %STR
Percent sign(%) : %NRSTR
Comma(,): %BQUOTE
Ampersand(&): %SUPERQ