cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • 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!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • 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
S_Boilermaker
Level II

Deleting Similar Rows

I'm trying to create a script that will delete a row from my table if the ID and two values are the same as the row before it. I cant delete all duplicate rows because there is a "run number" column that is unique to each row. Does anyone know why my code isn't working?
 
// Delete Duplicate Rows (re-entries)
NRows = N Rows(dt);
For(i = 1, i <= NRows, i++,
	If(
		dt:ID[i] == dt:ID[i + 1] & Data Table("Sheet1"):value1[i] == dt:value1[i + 1] & dt
		:value2[i] == dt:value2[i + 1],
		{dt << Delete Rows(i), i--}
	)
);
 
S_Boilermaker_0-1718371290032.png

 

1 REPLY 1

Re: Deleting Similar Rows

I think this portion of your script in the braces is where things are going wrong (the if() function doesn't generally want braces there):

{ dt << Delete Rows (i), i --}

That being said, here's another, perhaps simpler way to get what you want, using JMP's built-in function for selecting duplicates:

dt << Select Duplicate Rows ({:ID, :Value 1, :Value 2});
dt << delete rows;

Recommended Articles