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
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"
)
); Automation and ScriptingBasic Data Analysis and ModelingRe: Error with IF statementWhat are you trying to do?
Re: Error with IF statement1] 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"
Re: Error with IF statementUse << 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");
);Re: Error with IF statementUse @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.
Re: Error with IF statementThe 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?
Re: Error with IF statementThank you so much. This worked fine.
Re: Error with IF statementHi Craige,
Thank you for the explanation. Its clear now.