Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: How to extend the IF command in a formula? Equivalent of select;when;when;ot...

Topic Options

- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jul 22, 2013 1:24 AM
(8448 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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";

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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