14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

186 Programming Methods Chapter 8<br />

Lists and Expressions<br />

Table 8.1 Compare Eval, Name Expr, and Expr<br />

(Continued)<br />

Command and result<br />

NameExpr(x);<br />

a+b+c<br />

Expr(x);<br />

x<br />

Explanation<br />

Returns the expression that was stored in x, which is a+b+c (unpacks the<br />

outside layer).<br />

Returns the expression x (packs one layer).<br />

JSL also supports functions to access and traverse expressions, all of them either a name or a literal<br />

expression as an argument. In the following, expressionArg is either a single name or a compound<br />

expression to be taken literally.<br />

NArg(expressionArg) finds the number of arguments in expressionArg.<br />

The expressionArg can be a name holding an expression, an expression evaluated to an expression, or a<br />

literal expression quoted by Expr().<br />

NArg (name) obtains the expression held in name (it is not evaluated) and returns the number of<br />

arguments<br />

NArg (expression) evaluates expression and returns the number of arguments<br />

NArg (Expr(expression)) returns the number of arguments to literal expression.<br />

For example, if aExpr = {a+b,c,d,e+f+g};<br />

• NArg(aExpr) results in 4.<br />

• NArg(Arg(aExpr,4)) results in 3.<br />

• NArg(Expr({1,2,3,4})) results in 4.<br />

Head(expressionArg) returns the head of the expression without any arguments. If the expression is an<br />

infix, prefix, or postfix special character operator, then it is returned as the functional equivalent.<br />

The expressionArg can be a name holding an expression, an expression evaluated to an expression, or a<br />

literal expression quoted by Expr().<br />

For example, if aExpr = expr(a+b);<br />

• r = Head(aExpr) results in Add().<br />

• r = Head (Expr(sqrt(r))) results in Sqrt().<br />

• r = Head({1,2,3}) results in {} .<br />

Arg(expressionArg,indexArg) extracts the specified argument of the symbolic expression, resulting in<br />

an expression.<br />

For example,<br />

Arg(expressionArg,i) extracts the i th argument of expressionArg<br />

The expressionArg can be a name holding an expression, an expression evaluated to an expression, or a<br />

literal expression quoted by Expr().

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!