Hi all,
I am writing a script where I select a subset from a data table based on some criteria:
Example dt is my data table with column :Error_ID
I input: "dt_subset=dt<Now let us say the dt data table has no Error_ID==0 rows, the dt_subset is empty.
I would have expected an dt_subset to be a new data table with the same columns as table dt but 0 rows, so that if I then check whether "If( !Empty(dt_subset)...)" I get a false and I do not continue doing work on the empty dt_subset table.
Instead I get an error if I try to check the if dt_subset is empty.
Basically what I want to do is be able to check if the selection is empty. Do you have a solution?
Thank you for your help!
If you just wish to check if any rows are selected, you can use << Get Selected Rows
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
dt << Select Where(:age >= 20);
selrows = dt << Get Selected Rows;
If(N Items(selrows) == 0,
Throw("No rows selected");
);
When I still need empty table after such a filter, I generally do something like this
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
rows_of_interest = dt << Get Rows Where(:age >= 20);
If(N Items(rows_of_interest) > 0,
dt_subset = dt << Subset(Rows(rows_of_interest), Selected Columns(0), Output table("SUBSET"));
,
dt_subset = dt << Subset(Rows(1), Selected Columns(0), Output table("SUBSET"));
dt_subset << Delete Rows(1);
);
Show(N Rows(dt_subset)); // demo purposes
If you wish to check from the table which was not created
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
dt_subset = dt << Select Where(:age >= 20) << Subset(Selected Rows(1), Selected Columns(0), Output table("SUBSET"));
If(Is Empty(dt_subset),
Throw("No rows selected");
);
Write();