Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Tom_Watson
Level II

Another JMP Syntax Challenge..........::(

I'm trying to properly format an IF statement and can't get it to work after umpteen iterations.  Appreciate any help!

I have a data table with a column called "Process Step Description".....data type character

I have another column in the table called "Module Failures" that is data type numeric/continuous; I create it successfully using the script segment below

I want to set the value of the cell in the "Module Failures" column based upon the value in the "Process Step Description" cell, as follows:

Process Step Description..................Module Failures

Outgoing Quality Check.................... 0

Unit Fails............................................1

 

I have the following commands in my script; as far as I can tell everything functions properly except for the IF statement itself

dt<<New Column("Module Failures");
column ("Module Failures") << data type(Numeric, Format("Fixed Dec", 1,0));
column ("Module Failures") << Modeling Type(Continuous);


If (Process Step Description == "Unit Fails", ("Module Failures" = 1), ("Module Failures" =0) );

 

It could be something to do with the quotes as I always get confused by the single and double quote rules but I tried so many permutations and nothing seems to work

 

Thank you in advance

6 REPLIES 6
Highlighted
txnelson
Super User

Re: Another JMP Syntax Challenge..........::(

The issue you are having is that you are not scoping the column references properly.  When you reference a column in JSL, the column name is proceeded by a ":" to indicate this is a column reference.  While you can use the Column() function in open code to reference a column, typically this is used when referencing a column through a memory variable

myColumn = "Process Step Description";
column( myColumn ) << ……..

Below are 3 different ways to accomplish what you need.  I suggest that you study the code below, and read the Scripting Guide to gain a full understanding about the scoping of columns and memory variables

Names Default To Here( 1 );
dt = New Table( "Example",
	Add Rows( 10 ),
	New Column( "Proceess Step Description",
		Character,
		"Nominal",
		Set Values(
			{"Unit Fails", "Outgoing Quality Check", "Unit Fails", "Unit Fails",
			"Outgoing Quality Check", "Outgoing Quality Check", "Unit Fails",
			"Outgoing Quality Check", "Unit Fails", "Outgoing Quality Check"}
		)
	)
);

dt << New Column( "Module Failures" );
:Module Failures <<
data type( Numeric, Format( "Fixed Dec", 1, 0 ) );
:Module Failures << Modeling Type( Continuous );

For Each Row(
	If( :Proceess Step Description == "Unit Fails",
		:Module Failures = 1,
		:Module Failures = 0
	)
);

// Or you can define your new column as a formula column
dt << New Column( "Module Failures 2",
	data type( Numeric ),
	Format( "Fixed Dec", 1, 0 ),
	Modeling Type( Continuous ), 
	Formula(
		If( :Proceess Step Description == "Unit Fails",
			 1,
			 0
		)
	)
);

// or If the reference variable changes you may want to 
// use the As Column()
zippy="Process Step Description";
dt << New Column( "Module Failures 3",
	data type( Numeric ),
	Format( "Fixed Dec", 1, 0 ),
	Modeling Type( Continuous ), 
	Formula(
		If( as column(dt, zippy) == "Unit Fails",
			1,
			0
		)
	)
);

 

Jim
Highlighted
Tom_Watson
Level II

Re: Another JMP Syntax Challenge..........::(

Thank you very much!!  Of the options you presented, the formula implementation is the most intuitive to me; I thought maybe the "if" needed to be implemented as a formula, but wasn't sure; I replaced by existing script segment with that below.  Unfortunately, it still only returns a "." in the Module Failures data column, so something is still not right.  The new column is created and the data type is correct, but the "if logic" does not seem to be getting implemented.

 

Thanks for any further advice.  I could provide more info too if needed.

 

dt << New Column( "Module Failures",
    data type( Numeric ),
    Format( "Fixed Dec", 1, 0 ),
    Modeling Type( Continuous ),
    Formula( If( :Proceess Step Description == "Unit fails", 1, 0 ) )
);
Highlighted
txnelson
Super User

Re: Another JMP Syntax Challenge..........::(

Are there any messages in the log?

Can you attach a sample of your data?

Jim
Highlighted
pmroz
Super User

Re: Another JMP Syntax Challenge..........::(

Could it be as simple as a typo?  Change "Proceess" to "Process"

 

Highlighted
Tom_Watson
Level II

Re: Another JMP Syntax Challenge..........::(

Yes, that simple!  Works now; thanks much!

Highlighted

Re: Another JMP Syntax Challenge..........::(

By the way, you do not need the If() function for your purpose. The Equal() function (or the == operator in this case) returns 1 if the two arguments are of equal value or 0 if they are not. So this script is just a bit more concise.

 

dt << New Column( "Module Failures",
    data type( Numeric ),
    Format( "Fixed Dec", 1, 0 ),
    Modeling Type( Continuous ),
    Formula( :Process Step Description == "Unit fails" )
);
Learn it once, use it forever!
Article Labels