cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
vharibal
Level II

Error with IF statement

 
I am using an IF statement as shown below. When I run the script it only implements the "Open" command> the script doesnt even enter IF loop. 
 
I tried using "FOR EACH ROW" along with IF statement as shown in script 2 but it throws the following error 
 
 
vharibal_0-1689066871443.png
 
 
Any suggestions??
 

dt = Open ("C:\Users\NXF90574\Documents\NXP\Machine Learning\Script trial\fc data\fc_mcs11_evm_cluster_means.jmp");

IF( :"Ppk"n <= 2 ,
(
dt  << Select where( :"Ppk"n <=2 );	

dt_ppk = dt << subset (Output table("fc_mcs11_evm_cluster_means_low_ppk.jmp"), Selected Rows( 1 ), selected columns( 0 ));
dt_ppk << Save As("C:\Users\NXF90574\Documents\NXP\Machine Learning\Script trial\fc data\fc_mcs11_evm_cluster_means_low_ppk.jmp");
),

"PPk Good"		
);
dt = Open ("C:\Users\NXF90574\Documents\NXP\Machine Learning\Script trial\fc data\fc_mcs11_evm_cluster_means.jmp");

For each row(dt,
IF( :"Ppk"n <= 2 ,
(
dt  << Select where( :"Ppk"n <=2 );	

dt_ppk = dt << subset (Output table("fc_mcs11_evm_cluster_means_low_ppk.jmp"), Selected Rows( 1 ), selected columns( 0 ));
dt_ppk << Save As("C:\Users\NXF90574\Documents\NXP\Machine Learning\Script trial\fc data\fc_mcs11_evm_cluster_means_low_ppk.jmp");


),
"PPk Good"
	
)			
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Error with IF statement

Use << Get Rows Where to get the rows with Ppk <= 2 and then use if statements to check if items in that list is higher than 0

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

Show(Row()); // Row() is inmitialize as 0 which isn't valid row number in JMP
// -> :name; // won't return anything useful

rows_of_interest = dt << Get Rows Where(:height <= 60);

If(N Items(rows_of_interest) > 0,
	// perform actions
	Show("PPK NOK")
,
	Print("PPK OK");
);
-Jarmo

View solution in original post

7 REPLIES 7
jthi
Super User

Re: Error with IF statement

What are you trying to do?

-Jarmo
vharibal
Level II

Re: Error with IF statement

1] Opening a file 

2 ] Checking if column name Ppk <=2

    a] if yes then select rows with Ppk <=2 - subset them and save as another data table

    b] if no then display "PPk good"

jthi
Super User

Re: Error with IF statement

Use << Get Rows Where to get the rows with Ppk <= 2 and then use if statements to check if items in that list is higher than 0

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

Show(Row()); // Row() is inmitialize as 0 which isn't valid row number in JMP
// -> :name; // won't return anything useful

rows_of_interest = dt << Get Rows Where(:height <= 60);

If(N Items(rows_of_interest) > 0,
	// perform actions
	Show("PPK NOK")
,
	Print("PPK OK");
);
-Jarmo
Craige_Hales
Super User

Re: Error with IF statement

Use @jthi answer. But to explain what happened...

 

In your original two snippets, the first fails because there is no current row in the table so

 

:"Ppk"n <= 2

 

is comparing against a missing value; compares against missing are neither true or false and the true and false clause of the if are not executed (a surprising result if you don't know about missing values in JMP.)

dt=open("$sample_data/big class.jmp");

dt:age==14
.   <<< no row selected, result is missing

row()=5; dt:age==13
0 <<< LILLIE is 12

In the second example, ForEachRow does make each row the current row, one at a time, so the first problem is avoided. Based on the unable to save at row 2 message, I'm pretty sure the first subset table is hanging on to the filename and the second subset made from row 2 wants to save to the same file, which is already in use. (edit:) close(dt_ppk) might resolve that, but it would still be recreating the same file, over and over again.

Craige
vharibal
Level II

Re: Error with IF statement

Hi Craige,

 

Thank you for the explanation. Its clear now.

vharibal
Level II

Re: Error with IF statement

Thank you so much. This worked fine.

Re: Error with IF statement

The first argument to the If() function,

:"Ppk"n <= 2

is evaluated and compares a column reference or table variable to a numeric value. Is that what you want to do?

Do you have a column and a table variable that are both names Ppk?