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
poulravn
Level IV

How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

Hi, I want to be able, in a scripted formula, to assign a text string to column depending onthe values of another column.

For instance:

A  B

1  Low

2  Low

3  Low

4  Medium

5  Medium

6  Medium

7  High

8  High

9  High

10 High

How does the formula lok for this?  If(:A<=3,"Low",:A>=3 and :A<7,"Medium",:A>=7,"High") does not work.

I Base SAS there is a command, select(); when();when(); ; ; otherwise;end; It is the equivalent of this I am looking for.

Regards

Poul Ravn Sørensen

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

Hi Poul,

You've got the right idea, just the wrong logical operator.

In JSL the AND operator is &. So, your formula should be:

     If(:A <= 3, "Low",

        :A >= 3 & :A < 7, "Medium",

        :A >= 7, "High")

-Jeff

-Jeff

View solution in original post

5 REPLIES 5

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

You could use a format:

DATA HAVE;

DO A = 1 TO 10;

OUTPUT;

END;

RUN;

PROC FORMAT ;

VALUE RATING

LOW - 3  = "LOW"

4-6  = "MEDIUM"

7 - HIGH = "HIGH";

RUN;

DATA WANT;

  SET HAVE;

  B = PUT(A,RATING.);

RUN;

Or Using:

DATA WANT;

    ATTRIB C LENGTH = $6;

  SET HAVE;

/* B = PUT(A,RATING.);*/

      IF A <= 3 THEN C = "LOW";

  ELSE IF 4 <= A <= 6 THEN C = "MEDIUM";

  ELSE C = "HIGH";

RUN;

poulravn
Level IV

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

I am sorry. This is the SAS program version, but I was trying to find the JMP Script formula for the same. Should have been more precise. Exactly this example shows how you would sometimes prefer to have a more comprehensive Scripting Guide. I found nothing to help me in the guide.

Regards

Poul

djchavda
Level I

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

Hi,

Try this

if A <= 3 then B="Low";

else if A > 3 and A <= 6 then B="Medium";

else B="High";

poulravn
Level IV

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

Again I am sorry; this works fine in SAS but I am looking for the JMP Formula (based on IF, MATCH or CHOOSE?) that does the same.

Regards

Poul

Jeff_Perkinson
Community Manager Community Manager

Re: How to extend the IF command in a formula? Equivalent of select;when;when;otherwise;end;

Hi Poul,

You've got the right idea, just the wrong logical operator.

In JSL the AND operator is &. So, your formula should be:

     If(:A <= 3, "Low",

        :A >= 3 & :A < 7, "Medium",

        :A >= 7, "High")

-Jeff

-Jeff