Test Your MacroRay
SummaryA. Intro to macro1. Why macro?2. Components of macro language (macro variables, programs, facility interfaces, stor...
B. Method to create macro variable1. Open code using %let2. Inside a macro program3. Select into: in proc sql4. Call sympu...
C. Macro processing1. Macro Compiling2. Macro Expression & Quoting     Types: Text/Logic/Arithmetic     %eval and %syseval...
1. How do professionals pronounce ampersand(&) for the macro variable?
1. How do professionals pronounce ampersand(&) for the macro variable?"amper", not "ampersand"
2. Where does SAS store macro variables?
2. Where does SAS store macro variables?PDV, program data vectorSecond memory area
3. What is the title on the report in the following?%let dwarfs = 7;proc print data = awards; title There are were &dwarfs...
3. What is the title on the report in the following?%let dwarfs = 7;proc print data = awards; title There are were &dwarfs...
4. How to replace with macro variables?%let year = 2007;%let month = MAR;%let type = revenue;%let libinfo = company;Target...
4. How to replace with macro variables?%let year = 2007;            Whenever SAS encounters a%let month = MAR;            ...
5. What is the ???? in the following?%let mouse1 = Mickey;%let mouse2 = Minnie;%let mouse3 = Miss Bianca;%let num=2;%let t...
5. What is the ???? in the following?%let mouse1 = Mickey;                                   &&mouse&num%let mouse2 = Minn...
6. How to assign singleq with Oneill ?We have%let singleq = Oneill;%put &singleq;                        Is this the resul...
6. How to assign singleq with Oneill ?We have%let singleq = %str(O%neill);%put &singleq;Umatched quotation marks(): %STRPe...
Test your macro
Test your macro
Test your macro
Test your macro
Test your macro
Upcoming SlideShare
Loading in …5
×

Test your macro

1,394 views
1,266 views

Published on

A quick test of your macro skills

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,394
On SlideShare
0
From Embeds
0
Number of Embeds
844
Actions
Shares
0
Downloads
6
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Test your macro

  1. 1. Test Your MacroRay
  2. 2. SummaryA. Intro to macro1. Why macro?2. Components of macro language (macro variables, programs, facility interfaces, storage techniques)3. Macro variableUser defined/AutomaticGlobal/Local)4. Syntax
  3. 3. B. Method to create macro variable1. Open code using %let2. Inside a macro program3. Select into: in proc sql4. Call symput in data step
  4. 4. C. Macro processing1. Macro Compiling2. Macro Expression & Quoting Types: Text/Logic/Arithmetic %eval and %sysevalf %compfl and %compchar3. 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
  5. 5. 1. How do professionals pronounce ampersand(&) for the macro variable?
  6. 6. 1. How do professionals pronounce ampersand(&) for the macro variable?"amper", not "ampersand"
  7. 7. 2. Where does SAS store macro variables?
  8. 8. 2. Where does SAS store macro variables?PDV, program data vectorSecond memory area
  9. 9. 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 1939B. There are were 7 small statues awarded in 1939
  10. 10. 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 1939B. There are were 7 small statues awarded in 1939The macro facility does not "peak inside" code with single quotes to resolve macro variables.
  11. 11. 4. How to replace with macro variables?%let year = 2007;%let month = MAR;%let type = revenue;%let libinfo = company;Target:Libname company C:m dataproc print data = company.MAR2007; var revenuecanada revenueus;run;
  12. 12. 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 dataproc print data = &libinfo..&month&year; var &type.canada &type.us;run;
  13. 13. 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;
  14. 14. 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;
  15. 15. 6. How to assign singleq with Oneill ?We have%let singleq = Oneill;%put &singleq; Is this the result?Warning
  16. 16. 6. How to assign singleq with Oneill ?We have%let singleq = %str(O%neill);%put &singleq;Umatched quotation marks(): %STRPercent sign(%) : %NRSTRComma(,): %BQUOTEAmpersand(&): %SUPERQ

×