schrodingerscat
schrodingerscat

Reputation: 199

Creating a new column in JMP using an if condition from another column

I am very new in JMP so I am still feeling around. I want to create a new column called "Status" in JMP. This status is character and depends on the value of the column "Grade". If the value of the entry in column "Grade" is zero, the value of the entry in column "Status" should be "fail". If the "Grade" value is greater than 100, the entry in column "Status" should be "invalid". If the :Grade" value is less than 0, the "Status" value should be "invalid". This should be simple. But somehow, my script won't work:

dt = Current Data Table();
dt << New Column("Status", Character, Formula(
    If(:Name( "Grade" )==0, "fail",
       :Name( "Grade" )>100, "invalid",
       :Name( "Grade" )<0, "invalid")
));

Can you help me debug this script?

Upvotes: 2

Views: 13500

Answers (1)

jschroedl
jschroedl

Reputation: 4986

I just tried the script and the formula is working for me.

Here is some JSL which is a bit more complete which also adds the "Grade" column upon which "Status" depends.

dt = Current Data Table();
dt << New Column( "Grade",
        Numeric,
        "Continuous",
        Format( "Best", 12 ),
    );
dt << New Column( "Status",
        Character,
        "Nominal",
        Formula(
            If(
                :Grade == 0, "fail",
                :Grade > 100, "invalid",
                :Grade < 0, "invalid"
            )
        )
    );

Perhaps the issue is that you don't already have a data table opened with a Grade column? Here's a script to create a brand new table with the formula and some values.

New Table( "Grading Test",
    Add Rows( 7 ),
    New Column( "Grade",
        Numeric,
        "Continuous",
        Format( "Best", 12 ),
        Set Selected,
        Set Values( [45, 20, 100, 101, -4, 0, 120] )
    ),
    New Column( "Status",
        Character,
        "Nominal",
        Formula(
            If(
                :Grade == 0, "fail",
                :Grade > 100, "invalid",
                :Grade < 0, "invalid"
            )
        )
    )
);

I created that by interactively creating the table and using the red-triangle menu and selected "Copy Table Script".

I tried JMP 12.0, which version are you using?

Upvotes: 3

Related Questions