cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar

If statements in JSL

Is it possible to execute multiple statements from one if condition - like an if/then/do statement in SAS? How can it be done?
1 ACCEPTED SOLUTION

Accepted Solutions

Re: If statements in JSL

You bet. It's odd in JSL, but semicolons are subordinate to commas. So you can have statements in an if statement separated by semicolons.

If(,<statements separated by semicolons>).

View solution in original post

7 REPLIES 7

Re: If statements in JSL

You bet. It's odd in JSL, but semicolons are subordinate to commas. So you can have statements in an if statement separated by semicolons.

If(,<statements separated by semicolons>).

Re: If statements in JSL

JSL gives the appearance of a regular language with statements terminated by a semicolon. It is however, very much a function driven language, where you make function calls with lists of arguments separated by commas. Standard programming constructions such as loops and if statements are implemented as functions. The IF function can take multiple arguments, which act in condition expression-pairs:

If ( condition1, expression1, condition2, expression2, ..., final-expression )

Thus giving the structure of an if--elseif-else statement.

Each expression can consist of multiple lines of code delineated with a semicolon.

In fact, the semicolon is just an operator that implements the Glue function. Glue takes a list of JSL expressions separated by commas,

so for example:

a=1;
b=2;
c=a+b;


is just short-hand for

Glue(a=1,b=2,c=a+b)

All the JSL functions are listed with descriptions in the JSL Functions Index under Help>Indexes
pmroz
Super User

Re: If statements in JSL

The IF statement in JSL takes a little getting used to. For readability I use comments that mark the "THEN" and "ELSE" sections.

Regards,

Peter

Re: If statements in JSL

These boards take HTML?????

Wahoo!!!
pmroz
Super User

Re: If statements in JSL

I put a very brief description of how to post formatted code in this posting:

http://support.sas.com/forums/message.jspa?messageID=38882#38882

Regards,
Peter

Re: If statements in JSL

Wow, that's awesome, thanks! (sorry for hijacking this thread).
Badri
Level I

Re: If statements in JSL

All actions need to be separated by semicolon and then grouped using parenthesis.

The following example worked.

 

A=1;

if(A==1, (x=A*1; y=A*2;z=A*3), (x=A^1; y=A^2;z=A^3));

Print(x); Print(y); Print(z);

/*:

 

1

2

3

//:*/

A=2;

if(A==1, (x=A*1; y=A*2;z=A*3), (x=A^1; y=A^2;z=A^3));

Print(x); Print(y); Print(z);

 

/*:

 

2

4

8