cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
ValeriaL
Level I

subset selection is empty, return error

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<<select where (:Error_ID==0)<<subset(selected rows(1));" and I expect the dt_subset table to be filled by all the entries in the dt table where the column :Error_ID is 0.

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!

2 REPLIES 2
jthi
Super User

Re: subset selection is empty, return error

There are many different options You can check if selection is empty/no rows are found and then either use stop() or throw() to stop script execution (if it is suitable).

Names Default To Here(1);

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

dt << Select Where(:age == 100);
// you can check for selections in dt table
If(N Items(dt << get selected rows) == 0,
	Show("No selections done");
);

dt_subset = dt << Subset(Selected Rows(1));
// you can check for dt_subset
If(Is Empty(dt_subset),
	Show("No subset table");
);

rows_to_subset = dt << Get Rows Where(:age == 100);
If(N Items(rows_to_subset) == 0,
	Show("No rows found");
);
// dt_subset = dt << Subset(rows(rows_to_subset));
-Jarmo
ValeriaL
Level I

Re: subset selection is empty, return error

Hi Jarmo,

thank you for your reply. I had finally time to check this and I see that the following solution worked:

 

dt_subset = dt << Subset(Selected Rows(1));
// you can check for dt_subset
If(Is Empty(dt_subset),
	Show("No subset table");
);

The other two still returned errors: 

ValeriaL_0-1673972285189.png

So I will use the second suggestion.

 

Best Regards, Valeria

Recommended Articles