1 / 8

Macro Expressions

Macro Expressions. There are three types of macro expressions: text , logical , and arithmetic . A text expression is any combination of text, macro variables, macro functions, or macro calls. Text expressions are resolved to generate text. Here are some examples of text expressions:

bmarcus
Download Presentation

Macro Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Macro Expressions • There are three types of macro expressions: text, logical, and arithmetic. • A text expression is any combination of text, macro variables, macro functions, or macro calls. • Text expressions are resolved to generate text. Here are some examples of text expressions: • &BEGIN • %GETLINE • &PREFIX.PART&SUFFIX • %UPCASE(&ANSWER)

  2. Macro Expressions • Logical expressions and arithmetic expressions are sequences of operators and operands forming sets of instructions that are evaluated to produce a result. • An arithmetic expression contains an arithmetic operator. • A logical expression contains a logical operator.

  3. Macro Language Elements that Evaluate Arithmetic and Logical Expressions • %DO macro-variable=expression %TO expression<%BY expression>; • %DO %UNTIL (expression); • %DO %WHILE (expression); • %EVAL (expression); • %IF expression %THEN statement; • %QSCAN (argument, expression<,delimiters>) • %QSUBSTR (argument, expression<,expression>) • %SCAN (argument, expression,<delimiters>) • %SUBSTR (argument, expression<,expression>) • %SYSEVALF (expression, conversion-type)

  4. Example %let A=2; %let B=5; %let operator=+; %put The result of &A &operator &B is %eval(&A &operator &B).; When you submit these statements, the %PUT statement writes this line to the log: The result of 2 + 5 is 7.

  5. Macro Language Operators

  6. Examples %let a=%eval(1+2); %let b=%eval(10*3); %let c=%eval(4/2); %let i=%eval(5/3); %put The value of a is &a; %put The value of b is &b; %put The value of c is &c; %put The value of I is &i; When you submit these statements, the following messages appear in the log: The value of a is 3 The value of b is 30 The value of c is 2 The value of I is 1 • %let d=%eval(10.0+20.0); /*INCORRECT*/ • Because the %EVAL function supports only integer arithmetic, the macro processor does not convert a value containing a period character to a number, and the operands are evaluated as character operands. This statement produces the following error message: • ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 10.0+20.0

  7. Examples %let a=%sysevalf(10.0*3.0); %let b=%sysevalf(10.5+20.8); %let c=%sysevalf(5/3); %put 10.0*3.0 = &a; %put 10.5+20.8 = &b; %put 5/3 = &c; • The %PUT statements display the following messages in the log: 10.0*3.0 = 30 10.5+20.8 = 31.3 5/3 = 1.6666666667 • When the %SYSEVALF function evaluates arithmetic expressions, it temporarily converts the operands that represent numbers to floating point values.

  8. Examples • The %SYSEVALF function provides conversion type specifications: BOOLEAN,INTEGER, CEIL, and FLOOR. • For example, the following %PUT statements return 1, 2, 3, and 2 respectively: %let a=2.5; %put %sysevalf(&a,boolean); %put %sysevalf(&a,integer); %put %sysevalf(&a,ceil); %put %sysevalf(&a,floor);

More Related