SlideShare ist ein Scribd-Unternehmen logo
1 von 21
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

Weitere ähnliche Inhalte

Ähnlich wie Test your macro

SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1venkatam
 
A brief introduction to VoIP Drupal (webinar)
A brief introduction to VoIP Drupal (webinar)A brief introduction to VoIP Drupal (webinar)
A brief introduction to VoIP Drupal (webinar)Leo Burd
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentationrailsconf
 
Hello, Drupal? Building Drupal sites that make and receive phone calls
Hello, Drupal? Building Drupal sites that make and receive phone callsHello, Drupal? Building Drupal sites that make and receive phone calls
Hello, Drupal? Building Drupal sites that make and receive phone callsLeo Burd
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1venkatam
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]MomenMostafa
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
Sas® Macro Design Patterns
Sas® Macro Design PatternsSas® Macro Design Patterns
Sas® Macro Design PatternsMark Tabladillo
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
VoIP Drupal portfolio
VoIP Drupal portfolioVoIP Drupal portfolio
VoIP Drupal portfolioLeo Burd
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3venkatam
 
SPA Architecture Basics - Colombo JS meetup
SPA Architecture Basics - Colombo JS meetupSPA Architecture Basics - Colombo JS meetup
SPA Architecture Basics - Colombo JS meetupHasith Yaggahavita
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science ChallengeMark Nichols, P.E.
 
Data Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup GroupData Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup GroupDoug Needham
 
Productive Use of the Apache Spark Prompt with Sam Penrose
Productive Use of the Apache Spark Prompt with Sam PenroseProductive Use of the Apache Spark Prompt with Sam Penrose
Productive Use of the Apache Spark Prompt with Sam PenroseDatabricks
 

Ähnlich wie Test your macro (20)

SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
Designing code
Designing codeDesigning code
Designing code
 
A brief introduction to VoIP Drupal (webinar)
A brief introduction to VoIP Drupal (webinar)A brief introduction to VoIP Drupal (webinar)
A brief introduction to VoIP Drupal (webinar)
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
Hello, Drupal? Building Drupal sites that make and receive phone calls
Hello, Drupal? Building Drupal sites that make and receive phone callsHello, Drupal? Building Drupal sites that make and receive phone calls
Hello, Drupal? Building Drupal sites that make and receive phone calls
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
Sas® Macro Design Patterns
Sas® Macro Design PatternsSas® Macro Design Patterns
Sas® Macro Design Patterns
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
VoIP Drupal portfolio
VoIP Drupal portfolioVoIP Drupal portfolio
VoIP Drupal portfolio
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
 
SPA Architecture Basics - Colombo JS meetup
SPA Architecture Basics - Colombo JS meetupSPA Architecture Basics - Colombo JS meetup
SPA Architecture Basics - Colombo JS meetup
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science Challenge
 
Data Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup GroupData Science Challenge presentation given to the CinBITools Meetup Group
Data Science Challenge presentation given to the CinBITools Meetup Group
 
Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
Method::Signatures
Method::SignaturesMethod::Signatures
Method::Signatures
 
Productive Use of the Apache Spark Prompt with Sam Penrose
Productive Use of the Apache Spark Prompt with Sam PenroseProductive Use of the Apache Spark Prompt with Sam Penrose
Productive Use of the Apache Spark Prompt with Sam Penrose
 

Mehr von ray4hz

Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programmingray4hz
 
Cmu experimental design
Cmu experimental designCmu experimental design
Cmu experimental designray4hz
 
Moving from programmer to statistician
Moving from programmer to statisticianMoving from programmer to statistician
Moving from programmer to statisticianray4hz
 
Senior sas programmer
Senior sas programmerSenior sas programmer
Senior sas programmerray4hz
 
Clinical sas programmer
Clinical sas programmerClinical sas programmer
Clinical sas programmerray4hz
 
Career path for sas programmer
Career path for sas programmerCareer path for sas programmer
Career path for sas programmerray4hz
 
尽管去做——无压工作的艺术
尽管去做——无压工作的艺术尽管去做——无压工作的艺术
尽管去做——无压工作的艺术ray4hz
 
Visualization hang zhong
Visualization hang zhongVisualization hang zhong
Visualization hang zhongray4hz
 
Cdisc sdtm implementation_process _v1
Cdisc sdtm implementation_process _v1Cdisc sdtm implementation_process _v1
Cdisc sdtm implementation_process _v1ray4hz
 

Mehr von ray4hz (9)

Introduction to clinical sas programming
Introduction to clinical sas programmingIntroduction to clinical sas programming
Introduction to clinical sas programming
 
Cmu experimental design
Cmu experimental designCmu experimental design
Cmu experimental design
 
Moving from programmer to statistician
Moving from programmer to statisticianMoving from programmer to statistician
Moving from programmer to statistician
 
Senior sas programmer
Senior sas programmerSenior sas programmer
Senior sas programmer
 
Clinical sas programmer
Clinical sas programmerClinical sas programmer
Clinical sas programmer
 
Career path for sas programmer
Career path for sas programmerCareer path for sas programmer
Career path for sas programmer
 
尽管去做——无压工作的艺术
尽管去做——无压工作的艺术尽管去做——无压工作的艺术
尽管去做——无压工作的艺术
 
Visualization hang zhong
Visualization hang zhongVisualization hang zhong
Visualization hang zhong
 
Cdisc sdtm implementation_process _v1
Cdisc sdtm implementation_process _v1Cdisc sdtm implementation_process _v1
Cdisc sdtm implementation_process _v1
 

Test your macro

  • 2. 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
  • 3. 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
  • 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 do professionals pronounce ampersand(&) for the macro variable?
  • 6. 1. How do professionals pronounce ampersand(&) for the macro variable? "amper", not "ampersand"
  • 7. 2. Where does SAS store 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