BookmarkSubscribe
Community Trekker

## Get min / max of selected data

Hi

I would like to know the most efficient way to get the min and max of a subset of a column.   I realize could do a select where(), and actually use the table subset function, and summarize, but I need the script to loop through thousands of columns (unique criteria per column) and I think opening / closing tables via subset is too slow.

I was hoping to do a select where() to select the rows, and then somehow get the selected data into a list, and return the min and max of the list. I've tried several things but haven't had any success. Any ideas?

Here's a simple test script. In this case I would want to return the min = 66 and the max = 70.

clear log();

clear globals();

names default to here (1);

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

dtData = current data table();

dtData << clear select;

dtData << select where( :height > 65);

column("height") << set selected(1);

Thanks,

Mike

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Get min / max of selected data

Try <<get rows where() which should be faster than first selecting rows of interest.

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

rows = dtData << get rows where( :height > 65 );

min65 = Min( :height[rows] );

max65 = Max( :height[rows] );

Show( min65, max65 );

/*

min65 = 66;

max65 = 70;

*/

2 REPLIES 2
Super User

## Re: Get min / max of selected data

Try <<get rows where() which should be faster than first selecting rows of interest.

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

rows = dtData << get rows where( :height > 65 );

min65 = Min( :height[rows] );

max65 = Max( :height[rows] );

Show( min65, max65 );

/*

min65 = 66;

max65 = 70;

*/

Community Trekker

## Re: Get min / max of selected data

Thank you!  That is exactly the function i was looking for. I didn't realize that "get rows where()" existed... or that you could apply a list to the column and take a summary of that. Very nice.