cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
jlmbs
Level III

How to input user to select column names to change from categorical to continuous numeric values?

I have a script that parses csv files with different column headings. Some have categorical values which need to remain as categorical, whilst other columns contain categorical values but need to be changed into continuous numeric (e.g. columns A, B, C, D in the example below). Is it possible to write a JSL script that executes the script below regardless of the column name?
Not sure how feasible this is - Maybe asking the user to select which columns to change to numeric values? Or import the column names from a list written in another file?

Local( {old dt = Current Data Table()},
Current Data Table( dt_split);
For Each( {col, index},
{:'A'n, :'B'n, :'C'n, :'D'n,}
col << Data Type( Numeric ) << Set Modeling Type( "Continuous" ) <<
Set Field Width( 12 )
);
Current Data Table( old dt );
);

 

1 REPLY 1
txnelson
Super User

Re: How to input user to select column names to change from categorical to continuous numeric values?

The Col List Box() display object is probably the best item to use to request input from a user on what columns to process.  Here is the entry from the Scripting Index

txnelson_0-1659923726413.png

The example creates a display window that allows for the selection of columns from the data table

txnelson_1-1659923805054.png

From there, you can add instructions and also collect the selected columns to be processed

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "Select Columns",
text box("Select Columns that need to be converted to numeric/continuous"),
	Col List Box( all, width( 250 ), maxSelected( 1 ) ),
	lb = Col List Box(),
	button box("OK",
		selected columns = lb << get items
	)
);

Above the selected columns are placed into a JMP list called "selected columns" when the OK button is pressed.  You can also add to the button box, the simple looping through the values in the selected columns list, add change the Data Types and Modeling Types.

 

Jim