Presentation is loading. Please wait.

Presentation is loading. Please wait.

Two “identical” programs

Similar presentations


Presentation on theme: "Two “identical” programs"— Presentation transcript:

1 Two “identical” programs
proc logistic data=s5238.chdage outest=betas; model chd=age; run; proc logistic data=s5238.chdage outest=betas ; model chd=age;run; These programs give exactly the same answer – Why?

2 3 Program Flow Submit=>Input Stack=>Tokenization=>Compilation=>Execution

3 Program Flow A SAS program can be any combination of: DATA steps and PROC steps global statements SAS Component Language (SCL) Structured Query Language (SQL) SAS macro language When you submit a program, it is copied to a memory location called the input stack. Remind students here about the compile phase and the execution phase, which they learned in Prg1 and Prg2. Then tell students that we are going to learn what SAS does even before the compile phase.

4 Program Flow Input Stack SUBMIT Command data bonus; set orion.staff;
bonus=salary*.1; run; proc print;

5 Program Flow When SAS code is in the input stack, a component of SAS called the word scanner reads the text in the input stack, character by character, left to right, top to bottom and breaks the text into fundamental units called tokens data bonus ; Word Scanner Note that in this "program flow" animation/demo, there is no macro code. This is just the normal flow of straight SAS code. Later in this chapter, we will introduce the idea of macro triggers and show how this alters the program flow. set orion.staff; bonus=salary*.1; run; proc print; Input Stack

6 Program Flow The word scanner passes the tokens, one at a time, to the appropriate compiler, as the compiler demands. Compiler data bonus; set orion . staff ; Word Scanner bonus=salary*.1; run; proc print; Input Stack

7 Program Flow The compiler: Requests tokens until it receives a semicolon Performs a syntax check on the statement Repeats this process for each statement SAS: Suspends compilation when a step boundary is encountered Executes the compiled code if there are no compilation errors Repeats this process for each step

8 Tokenization The word scanner recognizes four classes of tokens: Name tokens Special tokens Literal tokens Number tokens Students might wonder here: Why do I need to know this? Assure them that we are leading up to the important concept of Macro Triggers, which consists of certain token combinations.

9 Name Tokens Name tokens contain one or more characters beginning with a letter or underscore and continuing with underscores, letters, or numerals. Examples: infile _n_ item3 univariate dollar10.2 Format and informat names contain a period.

10 Special Tokens Special tokens can be any character, or combination of characters, other than a letter, numeral, or underscore. Examples: This list is not all-inclusive. * / + - ** ; $ ( ) . & % @ # = ||

11 Literal Tokens A literal token is a string of characters enclosed in single or double quotation marks. Examples: 'Any text' "Any text" The string is treated as a unit by the compiler.

12 Number Tokens Number tokens can be integer numbers, including SAS date constants floating point numbers, containing a decimal point and/or exponent. Examples: '01jan2009'd 5E8 7.2E-4

13 Tokenization A token ends when the word scanner detects one of the following: the beginning of another token a blank after a token Blanks are not tokens. Blanks delimit tokens. The maximum length of a token is 32,767 characters.

14 Input Stack Tokens var x1-x z ; var x1 - x10 z ;

15 Input Stack Tokens title 'Report for May'; 1. title 2. 'Report for May' 3. ;

16 Macro Triggers During word scanning, two token sequences are recognized as macro triggers: %name-token a macro statement, function, or call &name-token a macro variable reference Finally! This is what we've been leading up to! The word scanner passes macro triggers to the macro processor.

17 Program Flow (Review) Compiler Word Scanner Input Stack

18 The Macro Processor The macro processor executes macro triggers, including macro language statements, macro functions, macro calls, and macro variable resolution, requesting tokens as necessary. Compiler Macro Processor Word Scanner Input Stack

19 Macro Statements Begin with a percent sign (%) followed by a name token End with a semicolon Represent macro triggers Are executed by the macro processor %let macvar=AMacroVariableValue; %put The value of macvar is: &macvar;

20 The %PUT Statement Writes text to the SAS log Writes to column one of the next line Writes a blank line if no text is specified General form of the %PUT statement: %PUT text; The instructor may wish to compare %PUT with PUT. The latter is a datastep statement. The former is a macro language statement. Also, this is a good time to say more generally that in the macro language, quote marks are rarely used. More on that subject later. Quotation marks are not required around text in %PUT statements. %PUT statements are valid in open code (anywhere in a SAS program).

21 %put Hello World!; The %PUT Statement
Example: Use a %PUT statement to write text to the SAS log. %put Hello World!;

22 Program Flow The %PUT statement is submitted. Compiler Macro Processor
Word Scanner Here is where we see that a macro trigger alters the program flow. Note that this is a macro language statement, not a SAS statement or step, as in the previous demo. Input Stack %put Hello World!; ...

23 Program Flow The statement is tokenized. Compiler Macro Processor
Word Scanner % put Hello World ! ; Input Stack ...

24 Program Flow When a macro trigger is encountered, it is passed to the macro processor for evaluation. Compiler Macro Processor Word Scanner %put Hello World ! ; Nothing is sent to the SAS compiler, because there are no SAS statements. Input Stack ...

25 Program Flow The macro processor requests tokens until a semicolon
is encountered. It then executes the macro statement. Compiler Macro Processor Word Scanner %put Hello World!; Input Stack ...

26 3 Program Flow Input Stack=>Tokenization=>Compilation=>Execution The macro facility

27 “The macro facility is a text processing facility for automating and customizing SAS code. The macro facility helps minimize the amount of SAS code you must type to perform common tasks.”


Download ppt "Two “identical” programs"

Similar presentations


Ads by Google