Here is an updated script that goes through each species in the iris data table and calculates the mean for the rows matching that criteria. That said, now that I better understand what you are doing, I would likely go about this differently and use tabulate to find those values instead.
Names default to here(1);
//Make a sample dataset with some excluded rows
dt = Open("$Sample_data/iris.jmp");
excluded rows to set = [ 4, 9, 52 ];
dt << Select Rows( excluded rows to set );
dt << Exclude(1);
species list = {"setosa", "versicolor", "virginica"};
//For each species
for(s=1, s<= n items (species list), s++,
//Find all matching rows and load in associative array, useful for Remove From function later
species matches = associative array(dt << Get Rows Where(:Species == species list[s]));
//get excluded rows
excluded rows = dt << get excluded rows();
//remove excluded rows from the list of rows matching the species
Remove From (species matches, excluded rows);
//get the matching rows as a list, use that to find which rows to average
mn = mean( :Sepal length[speciesmatches << get keys] );
//output averages to the log
write(species list[s] || " mean = " || char(mn) || "\!n")
);
Option using tabulate:
Names default to here(1);
//Make a sample dataset with some excluded rows
dt = Open("$Sample_data/iris.jmp");
excluded rows to set = [ 4, 9, 52 ];
dt << Select Rows( excluded rows to set );
dt << Exclude(1);
//New column with the check for each value
New Column("Species_", Character, "Nominal", Formula(If(Contains(:Species, "se"), "se", Contains(:Species, "ve"), "ve", Contains(:Species, "vi"), "vi")));
//tabulate to find averages - script copied from 'source' of data table after selecting
//'make into data table' from tabulate platform, then inserted dt reference
dtTab = (dt << Tabulate(
Set Format( Mean( :Sepal length( 10, 4 ) ) ),
Add Table(
Column Table( Analysis Columns( :Sepal length ), Statistics( Mean ) ),
Row Table( Grouping Columns( :Species_ ) )
)
)) << Make Into Data Table;
//Now get values from the table
dtTab:"Mean(Sepal length)"n[dtTab << Get Rows Where(:Species_ == "se")];