SAS macro High-Level Knowledge points

1. As a macro function, you do not need to enclose character values in quotation marks as you do in DATA step functions.

  One way in which macro language is different from SAS language is Macro-variable values are always text, quotation marks are not needed to indicate texr constants in the macro language.

  EXAMPLE

     dsid=open("sasuser.houses","i");                /*has quotation marks, because it's a DATA step function*/
     dsid=open("&mydata","&mode");
     %let dsid = %sysfunc(open(sasuser.houses,i));  /*has not quatation marks, becauese it's a macro funtion*/
     %let dsid=%sysfunc(open(&mydata,&mode));

2. the compile and execute process of sas program

  step-1: Submitted SAS programs start in the input stack.

  step-2: The word scanner takes statements from the input stack and tokenizes the statements into the fundamental units of words and symbols.

  step-3: The word scanner then direct the tokens to the DATA step compiler, macro processor, command processor or SCL compiler

  step-4: The compiler or processor that receives the tokens checks for synatax errors,if none are found, the step executes.

3.Understanding Tokens

  The fundamental building blocks of a SAS program are the tokens that the word scanner creates from your SAS language statements. Each word, literal string, number, and special symbol in the statement in your program is a token.

  The word scanner determines that a token ends when either a blank is found following a token or when another token begins. The maximum of a token unber SAS is 32767 characters.

  Two special symbol tokens, when followed by either a letter or underscore, signal the word scanner to turn processing over to the macro processor. These two characters, the ampersand (&) and the percent sign (%), are called macro triggers. 

   

The interactive between Macro-Language Processing and SAS-language Processing

  When the word scanner detects a macro trigger followed by a name token, it sends what follows to the macro processor and temporarily turn processing over the macro processor. The word scanner suspends tokenization while the macro processor completes its job. Therefore, processing of a macro language reference occurs after tokenization and before compilation.

  1. As your SAS programming assistant, the macro processor codes SAS language statements for you based on the guidelines you give it.

  2. The macro processor take the macro language statements you write and send non-macro text, such as SAS language statements, back to the input stack.

  3. The macro processor puts the non-macro text that it builds back on the top of the input stack.

  4. The word scanner then resumes its work by tokenizing the non-macro text it received from the macro processor.

     

原文地址:https://www.cnblogs.com/yican/p/4730213.html