Test your macro
description
Transcript of Test your macro
![Page 1: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/1.jpg)
Test Your Macro
Ray
![Page 2: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/2.jpg)
Summary
A. Intro to macro
1. Why macro?
2. Components of macro language (macro variables, programs, facility interfaces, storage techniques)
3. Macro variable
User defined/Automatic
Global/Local)
4. Syntax
![Page 3: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/3.jpg)
B. Method to create macro variable1. Open code using %let2. Inside a macro program3. Select into: in proc sql4. Call symput in data step
![Page 4: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/4.jpg)
C. Macro processing1. Macro Compiling2. Macro Expression & Quoting Types: Text/Logic/Arithmetic %eval and %sysevalf %compfl and %compchar 3. Storing & Reusing Macros Saving macros in an autocall library Calling an autocall macro Saving macros using the stored compiled macro facility
Calling a stored compiled macro
![Page 5: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/5.jpg)
1. How do professionals pronounce ampersand(&) for the macro variable?
![Page 6: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/6.jpg)
1. How do professionals pronounce ampersand(&) for the macro variable?
"amper", not "ampersand"
![Page 7: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/7.jpg)
2. Where does SAS store macro variables?
![Page 8: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/8.jpg)
2. Where does SAS store macro variables?
PDV, program data vector
Second memory area
![Page 9: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/9.jpg)
![Page 10: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/10.jpg)
![Page 11: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/11.jpg)
![Page 12: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/12.jpg)
![Page 13: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/13.jpg)
![Page 14: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/14.jpg)
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
![Page 15: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/15.jpg)
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.
![Page 16: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/16.jpg)
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;
![Page 17: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/17.jpg)
4. How to replace with macro variables?
%let year = 2007;
%let month = MAR;
%let type = revenue;
%let libinfo = company;
Answer:
Libname &libinfo 'C:\m data''
proc print data = &libinfo..&month&year;
var &type.canada &type.us;
run;
Whenever SAS encounters a period after a macro variable reference, the period is treated as a way to end the macro variable and then the period is thrown away.
![Page 18: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/18.jpg)
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;
![Page 19: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/19.jpg)
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 = "&&mouse&num";
title "&&mouse&num is my favorite character";
run;
&&mouse&num
&mouse2
Minnie
![Page 20: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/20.jpg)
6. How to assign singleq with O'neill ?
We have
%let singleq = O'neill;
%put &singleq; Is this the result?
Warning
![Page 21: Test your macro](https://reader035.fdocuments.us/reader035/viewer/2022081718/547a3da3b4af9f08688b46e7/html5/thumbnails/21.jpg)
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