cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

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

Delete columns with for loop

Hi,

 

I create a for loop script to delete empty column (column contains only N/A).

It works ok except on one file, one column get deleted when it's not suppose to.

Not sure what's wrong

 

for (i= ncols (dt[d]),i>=1,i--,
	summarize(data table(dt[d]),temp = by(column(i)));
	if(nitems(temp) ==1 & temp[1]=="N/A",
		data table(dt[d])<< delete columns(column(i));
	);
);



1 REPLY 1
jthi
Super User

Re: Delete columns with for loop

Add supporting prints inside your for loop to see what is going on with the one specific column. I usually like using Show()

Names Default To Here(1);

dt = {};

dt_u = New Table("Untitled",
	Add Rows(3),
	New Column("Column 1", Character, "Nominal", Set Values({"N/A", "N/A", "N/A"})),
	New Column("Column 2", Character, "Nominal", Set Values({"a", "", ""})),
	New Column("Column 3", Character, "Nominal", Set Values({"b", "", ""})),
	New Column("Column 4", Character, "Nominal", Set Values({"N/A", "N/A", ""}))
);
dt[1] = dt_u << get name;
d = 1;

For(i = N Cols(Datatable(dt[d])), i >= 1, i--,
	Summarize(Data Table(dt[d]), temp = by(Column(i)));
	If(i == 3,
		show(temp);
	);
	If(N Items(temp) == 1 & temp[1] == "N/A",
		show(temp);
		Data Table(dt[d]) << delete columns(Column(i))
	);
);
-Jarmo

Recommended Articles