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!

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