Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
sam_t
Level III

error exception during delete column

Hi,

 

For my code below, JMP crash for error exception. Any suggestion? Thanks.

 

csv_file = "C:/test4.csv";
CSV_data = Open( csv_file ); 

delList = {};
delColumns = {"Country", "Percent_Name_Count", "Name", "ID"};
nColumns = N Items( delColumns );

For( k = 1, k <= nColumns, k++, 
	For( i = 1, i<= N Cols(CSV_data), i++,
		If( Contains( Uppercase( as Column(  i ) << get name ), Uppercase(Char(delColumns[k])) ) > 0,
			insert into(delList, column(i)<<get name)
		)
	);
);

ndelList = N Items( delList );
If (ndelList > 0, CSV_data << delete columns( delList ));


test4.csv
ID,Name,Country,Column1_Value,Column2_Value_More,Percent_Name_Count
125480,Jack,CA,0.7,0.7,0.7
125481,Jane,US,0.69,0.69,0.69
125482,Joe,BZ,0.71,0.71,0.71
125483,Jim,FR,0.73,0.73,0.73
125484,Jerry,US,0.72,0.72,0.72
125485,John,CA,0.71,0.71,0.71
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: error exception during delete column

Your code worked without error on my Windows 10, 64bit, JMP 15.1.0.  However, your code was doing a lot more than it had to.  The Contains() function not only works on literal strings, it also works on Lists.  I modified you code below to get what you want by taking advantage of the way the Constraint() function works on lists.

csv_file = "C:/test4.csv";
CSV_data = Open( csv_file ); 

delList = {};
delColumns = {"Country", "Percent_Name_Count", "Name", "ID"};
nColumns = N Items( delColumns );

For( k = 1, k <= nColumns, k++,
	delColumns[k] = Uppercase( delColumns[k] )
);

For( i = 1, i <= N Cols( CSV_data ), i++,
	If( Contains( delColumns, Uppercase( Column( i ) << get name )) > 0,
		Insert Into( delList, Column( i ) << get name )
	)
);


ndelList = N Items( delList );
If( ndelList > 0,
	CSV_data << delete columns( delList )
);

 

Jim

View solution in original post

1 REPLY 1
Highlighted
txnelson
Super User

Re: error exception during delete column

Your code worked without error on my Windows 10, 64bit, JMP 15.1.0.  However, your code was doing a lot more than it had to.  The Contains() function not only works on literal strings, it also works on Lists.  I modified you code below to get what you want by taking advantage of the way the Constraint() function works on lists.

csv_file = "C:/test4.csv";
CSV_data = Open( csv_file ); 

delList = {};
delColumns = {"Country", "Percent_Name_Count", "Name", "ID"};
nColumns = N Items( delColumns );

For( k = 1, k <= nColumns, k++,
	delColumns[k] = Uppercase( delColumns[k] )
);

For( i = 1, i <= N Cols( CSV_data ), i++,
	If( Contains( delColumns, Uppercase( Column( i ) << get name )) > 0,
		Insert Into( delList, Column( i ) << get name )
	)
);


ndelList = N Items( delList );
If( ndelList > 0,
	CSV_data << delete columns( delList )
);

 

Jim

View solution in original post

Article Labels

    There are no labels assigned to this post.