Test Your Macro

Ray
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
B. Method to create macro variable
1. Open code using %let
2. Inside a macro program
3. Select into: in proc sql
4. Call symput in data step
C. Macro processing
1. Macro Compiling
2. 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
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 vector
Second 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 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
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.
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;
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;
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;
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;
6. How to assign singleq with O'neill ?

We have
%let singleq = O'neill;
%put &singleq;                        Is this the result?




Warning
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

Test your macro

  • 1.
  • 2.
    Summary A. Intro tomacro 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
  • 3.
    B. Method tocreate macro variable 1. Open code using %let 2. Inside a macro program 3. Select into: in proc sql 4. Call symput in data step
  • 4.
    C. Macro processing 1.Macro Compiling 2. 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
  • 5.
    1. How doprofessionals pronounce ampersand(&) for the macro variable?
  • 6.
    1. How doprofessionals pronounce ampersand(&) for the macro variable? "amper", not "ampersand"
  • 7.
    2. Where doesSAS store macro variables?
  • 8.
    2. Where doesSAS store macro variables? PDV, program data vector Second memory area
  • 14.
    3. What isthe 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 isthe 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 toreplace 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 toreplace 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 isthe ???? 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 isthe ???? 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 toassign singleq with O'neill ? We have %let singleq = O'neill; %put &singleq; Is this the result? Warning
  • 21.
    6. How toassign singleq with O'neill ? We have %let singleq = %str(O%'neill); %put &singleq; Umatched quotation marks('): %STR Percent sign(%) : %NRSTR Comma(,): %BQUOTE Ampersand(&): %SUPERQ