Presentation is loading. Please wait.

Presentation is loading. Please wait.

Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,

Similar presentations


Presentation on theme: "Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,"— 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 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( ); /*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:

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 = &b; %put 5/3 = &c; The %PUT statements display the following messages in the log: 10.0*3.0 = 30 = 31.3 5/3 = 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);


Download ppt "Macro Expressions There are three types of macro expressions: text, logical, and arithmetic. A text expression is any combination of text, macro variables,"

Similar presentations


Ads by Google