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
terapin
Level V

Create list of values corresponding to list of columns

I'm creating a list of potential column names that may be encountered in one of many data tables that are worked with, creating an actual list of columns found in the opened data table, and then trying to create a list of of values corresponding to the actual column list.  However, when I run the following code, it is grabbing the value from the first column in the list for all columns listed that I cycle through.  This code is resulting in a list = {13.975, 13.975} instead of {13.975, 105}.  I've tried various iterations for this but can't get the correct values.  Any suggestions would be greatly appreciated. 

Clear Log();

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

dt_col_name_list = dt << Get Column Names( String );

dtsum = dt << Summary( 
	Mean( Eval( dt_col_name_list ) ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" )
);


// Potential column name list
pot_col_list = {"age", "mass", "height", "length" };
dtsum_col_name_list = dtsum << Get Column Names( String );
show(dtsum_col_name_list);

// Create empty list to hold names of the those measurement variables found in data table
act_col_list = {};
col_list_cnt = {};

// Run through data table column names and put those that match measurement variable list into new list
For( i = 1, i <= N Items( pot_col_list ), i++,
	If( Contains( dtsum_col_name_list, pot_col_list[i] ),
		Insert Into( act_col_list, pot_col_list[i] );
		Insert Into( col_list_cnt, dtsum:pot_col_list[1,i] );
	)
);

Show( col_list_cnt );
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Create list of values corresponding to list of columns

The reference used to get the value from pot_col_list isn't valid, see below for a correction that appears to work

names default to here(1);
Clear Log();

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

dt_col_name_list = dt << Get Column Names( String );

dtsum = dt << Summary( 
	Mean( Eval( dt_col_name_list ) ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" )
);


// Potential column name list
pot_col_list = {"age", "mass", "height", "length" };
dtsum_col_name_list = dtsum << Get Column Names( String );
show(dtsum_col_name_list);

// Create empty list to hold names of the those measurement variables found in data table
act_col_list = {};
col_list_cnt = {};

// Run through data table column names and put those that match measurement variable list into new list
For( i = 1, i <= N Items( pot_col_list ), i++,
	If( Contains( dtsum_col_name_list, pot_col_list[i] ),
		Insert Into( act_col_list, pot_col_list[i] );
		Insert Into( col_list_cnt, column(dtsum,pot_col_list[i])[1] );
	)
);

Show( col_list_cnt );

 

Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Create list of values corresponding to list of columns

The reference used to get the value from pot_col_list isn't valid, see below for a correction that appears to work

names default to here(1);
Clear Log();

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

dt_col_name_list = dt << Get Column Names( String );

dtsum = dt << Summary( 
	Mean( Eval( dt_col_name_list ) ),
	Freq( "None" ),
	Weight( "None" ),
	statistics column name format( "column" )
);


// Potential column name list
pot_col_list = {"age", "mass", "height", "length" };
dtsum_col_name_list = dtsum << Get Column Names( String );
show(dtsum_col_name_list);

// Create empty list to hold names of the those measurement variables found in data table
act_col_list = {};
col_list_cnt = {};

// Run through data table column names and put those that match measurement variable list into new list
For( i = 1, i <= N Items( pot_col_list ), i++,
	If( Contains( dtsum_col_name_list, pot_col_list[i] ),
		Insert Into( act_col_list, pot_col_list[i] );
		Insert Into( col_list_cnt, column(dtsum,pot_col_list[i])[1] );
	)
);

Show( col_list_cnt );

 

Jim

View solution in original post

Highlighted
terapin
Level V

Re: Create list of values corresponding to list of columns

That did it txnelson,

 

Thanks for taking a look and help correct my syntax error.

Article Labels

    There are no labels assigned to this post.