SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Chapter 4. Macro Programs Venkata Maguluri
Basic Structure and Processing Macro Program
[object Object],[object Object],[object Object],[object Object],Macro Program
Defining a Macro ,[object Object],[object Object],[object Object],[object Object],[object Object],%MACRO  macro-name; macro-text ; %MEND  macro-name; Macro Program
Defining a Macro ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],%MACRO   macro-name ; macro-text %MEND   macro-name ; Macro Program
Macro Compilation ,[object Object],[object Object],[object Object],[object Object],[object Object],continued... Macro Program
[object Object],[object Object],[object Object],Macro Compilation Macro Program
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Macro Compilation Macro Program
[object Object],[object Object],Macro Compilation Macro Program
[object Object],[object Object],continued... Macro Compilation Macro Program
[object Object],[object Object],[object Object],[object Object],[object Object],Macro Compilation Macro Program
Submitting a macro definition compiles the macro. After the macro compiles successfully, you execute it with a macro call. General form of the macro call: %macro-name Calling a Macro Macro Program
[object Object],[object Object],[object Object],[object Object],Calling a Macro Macro Program
Example: Define a simple macro that produces code to print the first five observations from the most recently created SAS data set. %macro prtlast; proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; %mend; Calling a Macro Macro Program
Suppose a program consists of several program steps that create SAS data sets. If the macro PRTLAST is compiled, you can reference it  after  each step. Calling a Macro Macro Program
proc sort data=perm.courses out=courses; by course_code; run; %prtlast proc sort data=perm.schedule out=schedule; by begin_date; run; %prtlast proc sort data=perm.students out=students; by student_name; run; %prtlast Calling a Macro Macro Program
[object Object],[object Object],[object Object],Calling a Macro Macro Program
The macro facility has reserved words that cannot be used as macro names: ABEND  ABORT  ACT  ACTIVATE BQUOTE  BY CLEAR  CLOSE  CMS  COMANDR  COPY  DEACT DEL  DELETE DISPLAY DMIDSPLY DMISPLIT DO EDIT  ELSE  END  EVAL  FILE  GLOBAL GO  GOTO  IF  INC  INCLUDE  INDEX INFILE INPUT  KEYDEF  LENGTH  LET  LIST continued... Macro Program
LISTM  LOCAL  MACRO  MEND  METASYM NRBQUOTE NRQUOTE NRSTR  ON  OPEN  PAUSE  PUT QSCAN  QSUBSTR QSYSFUNC QUOTE  QUPCASE RESOLVE RETURN  RUN  SAVE  SCAN  STOP  STR SUBSTR  SUPERQ  SYSCALL  SYSEVALF SYSEXEC SYSFUNC SYSGET  SYSRPUT THEN  TO  TSO  UNQUOTE UNSTR  UNTIL  UPCASE  WHILE  WINDOW Reserved Words in the Macro Facility Macro Program
Example: Attempt to define a macro named PUT. SAS Log What ambiguity would result if you could define a macro named PUT? Reserved Words in the Macro Facility Macro Program
Macro Execution ,[object Object],[object Object],[object Object],[object Object],continued... Macro Program
Macro Execution ,[object Object],[object Object],Macro Execution Macro Program
Macro Execution During macro execution, the macro processor  can  communicate directly with: symbol tables storing values with %LET and resolving macro variable references  (&macvar ). the input stack generating SAS code for tokenization by the word scanner. During macro execution, the macro processor  cannot  communicate directly with SAS data sets to obtain or modify values of variables. Macro Execution Macro Program
[object Object],[object Object],[object Object],[object Object],Macro Execution continued... Macro Execution Macro Program
[object Object],[object Object],[object Object],Macro Execution Macro Execution Macro Program
%macro prtlast; proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; %mend; WORK.SASMACR.PRTLAST.MACRO Catalog Entry Original Input Stack %prtlast Macro Execution Macro Program
proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; Input Stack after Substitution of Text Partial SAS Log Why do you see a note from PROC PRINT, but not the PROC PRINT code itself? Macro Execution Macro Program
[object Object],[object Object],[object Object],[object Object],[object Object],Monitoring Execution Macro Program
The MPRINT option prints the text sent to the SAS compiler as a result of macro execution. General form of the MPRINT|NOMPRINT option: OPTIONS  MPRINT; OPTIONS  NOMPRINT; The default setting is NOMPRINT . Monitoring Execution Macro Program
The MLOGIC prints messages indicating macro actions taken during macro execution. General form of the MLOGIC|NOMLOGIC option: OPTIONS  MLOGIC; OPTIONS  NOMLOGIC; The default setting is NOMLOGIC. Monitoring Execution Macro Program
[object Object],[object Object],[object Object],[object Object],Monitoring Execution Macro Program
The MPRINT System Option ,[object Object],[object Object],[object Object],[object Object],Macro Program
SAS Log The macro variable reference is resolved. The MPRINT System Option Macro Program
[object Object],[object Object],[object Object],[object Object],[object Object],The MLOGIC System Option Macro Program
SAS Log Specify the MPRINT, MLOGIC, and SYMBOLGEN system options to obtain all possible information from the macro processor. The MLOGIC System Option Macro Program
Example: Successfully submit a macro definition and print a report showing where compiled macros are stored by default. %macro prtlast; proc print data=&syslast(obs=5); title "Listing of &sysast data set"; run; %mend; proc catalog cat=work.sasmacr; contents; title "Default Storage of SAS Macros"; quit; Macro Program
Partial PROC CATALOG Output The list of entries in a SAS catalog can also be obtained through the Catalog window. Macro Storage (Optional) Macro Program
Comments in Macro Programs (Optional) You can place comments within a macro definition with the macro comment statement. General form of the macro comment statement: %*  comment  ; comment  can be any message. Macro Program
Example: Use macro comments to describe the functionality of a macro. %macro printit; %* The value of &syslast will be substituted appropriately ; %* as long as a data set has been  created in this session. ; proc print data=&syslast(obs=5); /* Only print the first 5 observations */ title "Last Created Data Set Is &syslast"; run; %mend; Comments in Macro Programs (Optional) Macro Program
Macro Parameters
Objectives ,[object Object],[object Object],Macro Parameters
Suppose the compiled macro PRINTDSN contains a reference to macro variables DSN and VARS. %macro printdsn; proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend; You can modify the behavior of PRINTDSN by changing the value of macro variable DSN or VARS before you call the macro. Macro Parameters
Example: Substitute  perm.courses  for DSN and  course_code course_title days  for VARS at macro execution. %let dsn=perm.courses; %let vars=course_code course_title days; %printdsn Example: Substitute  perm.schedule  for DSN and  course_code location begin_date  for VARS at macro execution. %let dsn=perm.schedule; %let vars=course_code location begin_date; %printdsn Introduction Macro Parameters
A revised definition of the PRINTDSN macro has a  parameter list  in the %MACRO statement. This list contains names of macro variables referenced only within the macro. %macro printdsn(dsn,vars); proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend; Macro Parameters
General form of a macro definition with parameters: %MACRO  macro-name(parameter list ); text referencing parameter variables %MEND ; ,[object Object],[object Object],[object Object],Macro Parameter Lists Macro Parameters
To call a macro with parameters, specify the values to be assigned to the parameters in the macro call. General form of a macro call with parameters: %macro-name(parameter-values) Macro Parameter Lists Macro Parameters
[object Object],[object Object],[object Object],[object Object],Macro Parameter Lists Macro Parameters
To call the PRINTDSN macro and provide values for parameters DSN and VARS, you submit the following code: It substitutes  perm.courses  for DSN and  course_code course_title days  for VARS during macro execution. %printdsn(perm.courses, course_code course_title   days) Macro Parameter Lists Macro Parameters
You can later submit the following code: This code substitutes  perm.schedule  for DSN and  course_code location begin_date  for VARS during macro execution. %printdsn(perm.schedule,   course_title location   begin_date) Macro Parameter Lists Macro Parameters
Variables declared in a parameter list are always stored in a separate symbol table known as a  local tabl e. The macro call %printdsn(perm.courses,course_code   course_title days) initializes a local table: Global Table  Local Table global variables DSN  perm.courses VARS  course_code   course_title days Macro Parameters
[object Object],[object Object],[object Object],[object Object],Macro Parameters
You can define macros with  positional  parameters. General form of a macro definition with positional parameters: %MACRO  macro-name(positional-1, ...,positional-n ); text referencing parameter variables %MEND ; Macro Parameters
[object Object],[object Object],Positional parameter variables in the %MACRO statement are Macro Parameters
General form of a call to a macro defined with positional parameters: %macro-name(value-1, ...,value-n) ,[object Object],[object Object],[object Object],value-1, ...,value-n Macro Parameters
Macros with Keyword Parameters Program: c04s2d1.sas ,[object Object],Macro Parameters
Macros with Keyword Parameters You can also define macros with  keyword  parameters. General form of a  macro definition  with keyword parameters : %MACRO  macro-name(keyword=value, ...,keyword=value ); text referencing parameter variables %MEND ; Macro Parameters
[object Object],[object Object],[object Object],[object Object],Keyword parameter variables in the %MACRO statement are Macros with Keyword Parameters Macro Parameters
General form of a  call to a macro  defined with keyword parameters : %macro-name(keyword=value, ...,keyword=value) Macros with Keyword Parameters Macro Parameters
[object Object],[object Object],[object Object],keyword=value, ...,keyword=value Macros with Keyword Parameters Macro Parameters
Macros with Keyword Parameters ,[object Object],Macro Parameters
You can also define macros with a parameter list containing both positional and keyword parameters. General form of a macro definition with mixed parameters: %MACRO  macro-name(positional-1, ...,positional-n , keyword=value, ...,keyword=value ); text referencing parameter variables %MEND ; All positional parameter variables in the %MACRO statement must be listed before any keyword parameter variable. Macros with Mixed Parameter Lists Macro Parameters
General form of a call to a macro defined with mixed parameters: %macro-name(value-1, ...,value-n , keyword=value, ...,keyword=valu e) Positional values must be listed before any keyword parameter in the macro call. Macros with Mixed Parameter Lists Macro Parameters
Macros with Keyword Parameters ,[object Object],[object Object],[object Object],[object Object],Macro Parameters
For macros defined with a parameter list, the token after  %macro-name  triggers macro execution. Therefore, to use all default parameter values, use the call  %attend() .  The call  %attend  will not execute until another token is encountered. Caution Macros with Keyword Parameters Macro Parameters
Tips on Writing Macro-Based Programs ,[object Object],continued... Macro Parameters
[object Object],continued... Tips on Writing Macro-Based Programs Macro Parameters
[object Object],Tips on Writing Macro-Based Programs Macro Parameters

Weitere ähnliche Inhalte

Was ist angesagt?

Utility Procedures in SAS
Utility Procedures in SASUtility Procedures in SAS
Utility Procedures in SASguest2160992
 
Stanの事後処理 LTver
Stanの事後処理 LTverStanの事後処理 LTver
Stanの事後処理 LTverdaiki hojo
 
Rで計量時系列分析~CRANパッケージ総ざらい~
Rで計量時系列分析~CRANパッケージ総ざらい~ Rで計量時系列分析~CRANパッケージ総ざらい~
Rで計量時系列分析~CRANパッケージ総ざらい~ Takashi J OZAKI
 
RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門Masaki Tsuda
 
xtsパッケージで時系列解析
xtsパッケージで時系列解析xtsパッケージで時系列解析
xtsパッケージで時系列解析Nagi Teramo
 
Stan勉強会資料(前編)
Stan勉強会資料(前編) Stan勉強会資料(前編)
Stan勉強会資料(前編) daiki hojo
 
Basics Of SAS Programming Language
Basics Of SAS Programming LanguageBasics Of SAS Programming Language
Basics Of SAS Programming Languageguest2160992
 
StanとRでベイズ統計モデリング 1,2章
StanとRでベイズ統計モデリング 1,2章StanとRでベイズ統計モデリング 1,2章
StanとRでベイズ統計モデリング 1,2章Miki Katsuragi
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processingguest2160992
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureYesAnalytics
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questionsDr P Deepak
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Hiroshi Shimizu
 
Oracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoOracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoSatoshi Kato
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデルHiroshi Shimizu
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SASizahn
 

Was ist angesagt? (20)

Utility Procedures in SAS
Utility Procedures in SASUtility Procedures in SAS
Utility Procedures in SAS
 
Stanの事後処理 LTver
Stanの事後処理 LTverStanの事後処理 LTver
Stanの事後処理 LTver
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
 
Rで計量時系列分析~CRANパッケージ総ざらい~
Rで計量時系列分析~CRANパッケージ総ざらい~ Rで計量時系列分析~CRANパッケージ総ざらい~
Rで計量時系列分析~CRANパッケージ総ざらい~
 
RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門
 
xtsパッケージで時系列解析
xtsパッケージで時系列解析xtsパッケージで時系列解析
xtsパッケージで時系列解析
 
Stan勉強会資料(前編)
Stan勉強会資料(前編) Stan勉強会資料(前編)
Stan勉強会資料(前編)
 
Basics Of SAS Programming Language
Basics Of SAS Programming LanguageBasics Of SAS Programming Language
Basics Of SAS Programming Language
 
INTRODUCTION TO SAS
INTRODUCTION TO SASINTRODUCTION TO SAS
INTRODUCTION TO SAS
 
StanとRでベイズ統計モデリング 1,2章
StanとRでベイズ統計モデリング 1,2章StanとRでベイズ統計モデリング 1,2章
StanとRでベイズ統計モデリング 1,2章
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 
Basics of SAS
Basics of SASBasics of SAS
Basics of SAS
 
Sas Plots Graphs
Sas Plots GraphsSas Plots Graphs
Sas Plots Graphs
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report Procedure
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説
 
7 主成分分析
7 主成分分析7 主成分分析
7 主成分分析
 
Oracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoOracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslasso
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデル
 
Introduction to SAS
Introduction to SASIntroduction to SAS
Introduction to SAS
 

Andere mochten auch

Presse nord vaudois samedi 12 13 février 2005
Presse nord vaudois samedi 12 13 février 2005Presse nord vaudois samedi 12 13 février 2005
Presse nord vaudois samedi 12 13 février 2005Sylvie Villa
 
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...Yvonne Lee
 
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...Yvonne Lee
 
Figurative language
Figurative languageFigurative language
Figurative languageJoel McGill
 
El valor de seis balones y doce pares de botas
El valor de seis balones y doce pares de botasEl valor de seis balones y doce pares de botas
El valor de seis balones y doce pares de botasLola Arroyo
 
Pacser prezentacio
Pacser prezentacioPacser prezentacio
Pacser prezentacioiskolanerina
 
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patientsYvonne Lee
 
Célula evangelista (quita las cosas que no te dejan avanzar)
Célula evangelista (quita las cosas que no te dejan avanzar)Célula evangelista (quita las cosas que no te dejan avanzar)
Célula evangelista (quita las cosas que no te dejan avanzar)Jesus Quiñonez
 
Market Research
Market ResearchMarket Research
Market ResearchEPAYNE52
 
METHODS TO MOTIVATE A CHILD
METHODS TO MOTIVATE A CHILDMETHODS TO MOTIVATE A CHILD
METHODS TO MOTIVATE A CHILDganukhandare7
 
AACR 2013 abstract featured in HematologyTimes
AACR 2013 abstract featured in HematologyTimesAACR 2013 abstract featured in HematologyTimes
AACR 2013 abstract featured in HematologyTimesYvonne Lee
 
Research methology intro_ YL
Research methology intro_ YLResearch methology intro_ YL
Research methology intro_ YLYvonne Lee
 
Consumer Insight Report March 2016
Consumer Insight Report March 2016Consumer Insight Report March 2016
Consumer Insight Report March 2016Ebony Moore
 
Creare un WebGIS - versione 0.1
Creare un WebGIS - versione 0.1Creare un WebGIS - versione 0.1
Creare un WebGIS - versione 0.1City Planner
 
Abc, gcb and doule hit diffuse large b
Abc, gcb and doule hit diffuse large bAbc, gcb and doule hit diffuse large b
Abc, gcb and doule hit diffuse large bGita Bhat
 

Andere mochten auch (20)

Presse nord vaudois samedi 12 13 février 2005
Presse nord vaudois samedi 12 13 février 2005Presse nord vaudois samedi 12 13 février 2005
Presse nord vaudois samedi 12 13 février 2005
 
T.SMITH
T.SMITHT.SMITH
T.SMITH
 
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...
AACR 2013 (#2539) Survival of lymphoma and beverages consumption; alcohol, te...
 
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...
ASCO 2012 Abstract Effect of sunlight exposure on survival in patients with l...
 
Figurative language
Figurative languageFigurative language
Figurative language
 
El valor de seis balones y doce pares de botas
El valor de seis balones y doce pares de botasEl valor de seis balones y doce pares de botas
El valor de seis balones y doce pares de botas
 
Pacser prezentacio
Pacser prezentacioPacser prezentacio
Pacser prezentacio
 
latest cv (2)
latest cv (2)latest cv (2)
latest cv (2)
 
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients
2016 ESMO Asia - Prognostic factors among ER+HER2- breast cancer patients
 
Célula evangelista (quita las cosas que no te dejan avanzar)
Célula evangelista (quita las cosas que no te dejan avanzar)Célula evangelista (quita las cosas que no te dejan avanzar)
Célula evangelista (quita las cosas que no te dejan avanzar)
 
asasProposal word bener
asasProposal word benerasasProposal word bener
asasProposal word bener
 
Market Research
Market ResearchMarket Research
Market Research
 
METHODS TO MOTIVATE A CHILD
METHODS TO MOTIVATE A CHILDMETHODS TO MOTIVATE A CHILD
METHODS TO MOTIVATE A CHILD
 
AACR 2013 abstract featured in HematologyTimes
AACR 2013 abstract featured in HematologyTimesAACR 2013 abstract featured in HematologyTimes
AACR 2013 abstract featured in HematologyTimes
 
Research methology intro_ YL
Research methology intro_ YLResearch methology intro_ YL
Research methology intro_ YL
 
Consumer Insight Report March 2016
Consumer Insight Report March 2016Consumer Insight Report March 2016
Consumer Insight Report March 2016
 
Spark Jobserver
Spark JobserverSpark Jobserver
Spark Jobserver
 
Eric peterson wac
Eric peterson wacEric peterson wac
Eric peterson wac
 
Creare un WebGIS - versione 0.1
Creare un WebGIS - versione 0.1Creare un WebGIS - versione 0.1
Creare un WebGIS - versione 0.1
 
Abc, gcb and doule hit diffuse large b
Abc, gcb and doule hit diffuse large bAbc, gcb and doule hit diffuse large b
Abc, gcb and doule hit diffuse large b
 

Ähnlich wie Sas macros part 4.1

SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2venkatam
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1venkatam
 
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureWake Tech BAS
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)Selomon birhane
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-ivShaniya Fathimuthu
 
Advanced Web Browser Automation
Advanced Web Browser Automation Advanced Web Browser Automation
Advanced Web Browser Automation Mathias Roth
 
Macros...presentation
Macros...presentationMacros...presentation
Macros...presentationfika sweety
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfacsmadurai
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical ToolsJoselito Perez
 
ELENA MICROPROCESSOR
ELENA MICROPROCESSORELENA MICROPROCESSOR
ELENA MICROPROCESSORranjeetdon
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobolSrinimf-Slides
 
SAS macro processing vs with out macro processing
SAS macro processing vs with out macro processingSAS macro processing vs with out macro processing
SAS macro processing vs with out macro processingSAYAN DAS
 
When best to use the %let statement, the symput routine, or the into clause t...
When best to use the %let statement, the symput routine, or the into clause t...When best to use the %let statement, the symput routine, or the into clause t...
When best to use the %let statement, the symput routine, or the into clause t...Arthur8898
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorialhughpearse
 

Ähnlich wie Sas macros part 4.1 (20)

Module 5.pdf
Module 5.pdfModule 5.pdf
Module 5.pdf
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
 
handout6.pdf
handout6.pdfhandout6.pdf
handout6.pdf
 
Ss4
Ss4Ss4
Ss4
 
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
33443223 system-software-unit-iv
33443223 system-software-unit-iv33443223 system-software-unit-iv
33443223 system-software-unit-iv
 
Advanced Web Browser Automation
Advanced Web Browser Automation Advanced Web Browser Automation
Advanced Web Browser Automation
 
Macros...presentation
Macros...presentationMacros...presentation
Macros...presentation
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
 
Unit 2
Unit 2Unit 2
Unit 2
 
ELENA MICROPROCESSOR
ELENA MICROPROCESSORELENA MICROPROCESSOR
ELENA MICROPROCESSOR
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
 
Handout#04
Handout#04Handout#04
Handout#04
 
SAS macro processing vs with out macro processing
SAS macro processing vs with out macro processingSAS macro processing vs with out macro processing
SAS macro processing vs with out macro processing
 
When best to use the %let statement, the symput routine, or the into clause t...
When best to use the %let statement, the symput routine, or the into clause t...When best to use the %let statement, the symput routine, or the into clause t...
When best to use the %let statement, the symput routine, or the into clause t...
 
Buffer overflow tutorial
Buffer overflow tutorialBuffer overflow tutorial
Buffer overflow tutorial
 
224-2009
224-2009224-2009
224-2009
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 

Kürzlich hochgeladen (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Sas macros part 4.1

  • 1. Chapter 4. Macro Programs Venkata Maguluri
  • 2. Basic Structure and Processing Macro Program
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. Submitting a macro definition compiles the macro. After the macro compiles successfully, you execute it with a macro call. General form of the macro call: %macro-name Calling a Macro Macro Program
  • 13.
  • 14. Example: Define a simple macro that produces code to print the first five observations from the most recently created SAS data set. %macro prtlast; proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; %mend; Calling a Macro Macro Program
  • 15. Suppose a program consists of several program steps that create SAS data sets. If the macro PRTLAST is compiled, you can reference it after each step. Calling a Macro Macro Program
  • 16. proc sort data=perm.courses out=courses; by course_code; run; %prtlast proc sort data=perm.schedule out=schedule; by begin_date; run; %prtlast proc sort data=perm.students out=students; by student_name; run; %prtlast Calling a Macro Macro Program
  • 17.
  • 18. The macro facility has reserved words that cannot be used as macro names: ABEND ABORT ACT ACTIVATE BQUOTE BY CLEAR CLOSE CMS COMANDR COPY DEACT DEL DELETE DISPLAY DMIDSPLY DMISPLIT DO EDIT ELSE END EVAL FILE GLOBAL GO GOTO IF INC INCLUDE INDEX INFILE INPUT KEYDEF LENGTH LET LIST continued... Macro Program
  • 19. LISTM LOCAL MACRO MEND METASYM NRBQUOTE NRQUOTE NRSTR ON OPEN PAUSE PUT QSCAN QSUBSTR QSYSFUNC QUOTE QUPCASE RESOLVE RETURN RUN SAVE SCAN STOP STR SUBSTR SUPERQ SYSCALL SYSEVALF SYSEXEC SYSFUNC SYSGET SYSRPUT THEN TO TSO UNQUOTE UNSTR UNTIL UPCASE WHILE WINDOW Reserved Words in the Macro Facility Macro Program
  • 20. Example: Attempt to define a macro named PUT. SAS Log What ambiguity would result if you could define a macro named PUT? Reserved Words in the Macro Facility Macro Program
  • 21.
  • 22.
  • 23. Macro Execution During macro execution, the macro processor can communicate directly with: symbol tables storing values with %LET and resolving macro variable references (&macvar ). the input stack generating SAS code for tokenization by the word scanner. During macro execution, the macro processor cannot communicate directly with SAS data sets to obtain or modify values of variables. Macro Execution Macro Program
  • 24.
  • 25.
  • 26. %macro prtlast; proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; %mend; WORK.SASMACR.PRTLAST.MACRO Catalog Entry Original Input Stack %prtlast Macro Execution Macro Program
  • 27. proc print data=&syslast(obs=5); title "Listing of &syslast data set"; run; Input Stack after Substitution of Text Partial SAS Log Why do you see a note from PROC PRINT, but not the PROC PRINT code itself? Macro Execution Macro Program
  • 28.
  • 29. The MPRINT option prints the text sent to the SAS compiler as a result of macro execution. General form of the MPRINT|NOMPRINT option: OPTIONS MPRINT; OPTIONS NOMPRINT; The default setting is NOMPRINT . Monitoring Execution Macro Program
  • 30. The MLOGIC prints messages indicating macro actions taken during macro execution. General form of the MLOGIC|NOMLOGIC option: OPTIONS MLOGIC; OPTIONS NOMLOGIC; The default setting is NOMLOGIC. Monitoring Execution Macro Program
  • 31.
  • 32.
  • 33. SAS Log The macro variable reference is resolved. The MPRINT System Option Macro Program
  • 34.
  • 35. SAS Log Specify the MPRINT, MLOGIC, and SYMBOLGEN system options to obtain all possible information from the macro processor. The MLOGIC System Option Macro Program
  • 36. Example: Successfully submit a macro definition and print a report showing where compiled macros are stored by default. %macro prtlast; proc print data=&syslast(obs=5); title "Listing of &sysast data set"; run; %mend; proc catalog cat=work.sasmacr; contents; title "Default Storage of SAS Macros"; quit; Macro Program
  • 37. Partial PROC CATALOG Output The list of entries in a SAS catalog can also be obtained through the Catalog window. Macro Storage (Optional) Macro Program
  • 38. Comments in Macro Programs (Optional) You can place comments within a macro definition with the macro comment statement. General form of the macro comment statement: %* comment ; comment can be any message. Macro Program
  • 39. Example: Use macro comments to describe the functionality of a macro. %macro printit; %* The value of &syslast will be substituted appropriately ; %* as long as a data set has been created in this session. ; proc print data=&syslast(obs=5); /* Only print the first 5 observations */ title "Last Created Data Set Is &syslast"; run; %mend; Comments in Macro Programs (Optional) Macro Program
  • 41.
  • 42. Suppose the compiled macro PRINTDSN contains a reference to macro variables DSN and VARS. %macro printdsn; proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend; You can modify the behavior of PRINTDSN by changing the value of macro variable DSN or VARS before you call the macro. Macro Parameters
  • 43. Example: Substitute perm.courses for DSN and course_code course_title days for VARS at macro execution. %let dsn=perm.courses; %let vars=course_code course_title days; %printdsn Example: Substitute perm.schedule for DSN and course_code location begin_date for VARS at macro execution. %let dsn=perm.schedule; %let vars=course_code location begin_date; %printdsn Introduction Macro Parameters
  • 44. A revised definition of the PRINTDSN macro has a parameter list in the %MACRO statement. This list contains names of macro variables referenced only within the macro. %macro printdsn(dsn,vars); proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend; Macro Parameters
  • 45.
  • 46. To call a macro with parameters, specify the values to be assigned to the parameters in the macro call. General form of a macro call with parameters: %macro-name(parameter-values) Macro Parameter Lists Macro Parameters
  • 47.
  • 48. To call the PRINTDSN macro and provide values for parameters DSN and VARS, you submit the following code: It substitutes perm.courses for DSN and course_code course_title days for VARS during macro execution. %printdsn(perm.courses, course_code course_title days) Macro Parameter Lists Macro Parameters
  • 49. You can later submit the following code: This code substitutes perm.schedule for DSN and course_code location begin_date for VARS during macro execution. %printdsn(perm.schedule, course_title location begin_date) Macro Parameter Lists Macro Parameters
  • 50. Variables declared in a parameter list are always stored in a separate symbol table known as a local tabl e. The macro call %printdsn(perm.courses,course_code course_title days) initializes a local table: Global Table Local Table global variables DSN perm.courses VARS course_code course_title days Macro Parameters
  • 51.
  • 52. You can define macros with positional parameters. General form of a macro definition with positional parameters: %MACRO macro-name(positional-1, ...,positional-n ); text referencing parameter variables %MEND ; Macro Parameters
  • 53.
  • 54.
  • 55.
  • 56. Macros with Keyword Parameters You can also define macros with keyword parameters. General form of a macro definition with keyword parameters : %MACRO macro-name(keyword=value, ...,keyword=value ); text referencing parameter variables %MEND ; Macro Parameters
  • 57.
  • 58. General form of a call to a macro defined with keyword parameters : %macro-name(keyword=value, ...,keyword=value) Macros with Keyword Parameters Macro Parameters
  • 59.
  • 60.
  • 61. You can also define macros with a parameter list containing both positional and keyword parameters. General form of a macro definition with mixed parameters: %MACRO macro-name(positional-1, ...,positional-n , keyword=value, ...,keyword=value ); text referencing parameter variables %MEND ; All positional parameter variables in the %MACRO statement must be listed before any keyword parameter variable. Macros with Mixed Parameter Lists Macro Parameters
  • 62. General form of a call to a macro defined with mixed parameters: %macro-name(value-1, ...,value-n , keyword=value, ...,keyword=valu e) Positional values must be listed before any keyword parameter in the macro call. Macros with Mixed Parameter Lists Macro Parameters
  • 63.
  • 64. For macros defined with a parameter list, the token after %macro-name triggers macro execution. Therefore, to use all default parameter values, use the call %attend() . The call %attend will not execute until another token is encountered. Caution Macros with Keyword Parameters Macro Parameters
  • 65.
  • 66.
  • 67.