Subscribe Bookmark RSS Feed

Problem of data filter by using for loop

blue1994

Contributor

Joined:

Feb 27, 2017

Hi, all
I now have face problem to filter out the data.I have 2 problems here:

Problem 1:How I can convert @ into character ?? Because when i run the script, it comes out error.

Group(
:Name( "I_P2A .6/.045 Avg @ ET" ),
:Name( "I_N2A .3/.045 Avg @ ET" ),
:Name( "I_P2G_G_0.6/0.06 Avg @ ET" ),
:Name( "I_P2HG_0.6/0.06 Avg @ ET" )
),
Freq( "None" ),
Weight( "None" )

 

Problem 2:  data filter by using loop.

Is it possible that if i want to group the 4 parameters below into one name(declare name)?

Because in my dataset, the column name are such as : I_P2A .6/.045 Avg @ ET
                                                                                        I_N2A .3/.045 Avg @ ET
                                                                                        I_P2G_G_0.6/0.06 Avg @ ET
                                                                                        I_P2HG_0.6/0.06 Avg @ ET

So, my purpose is how can i make 4 column into one names, because when i write out the script, i only need to write the variables names that i declare(4 parameters), then it will automate to know these 4  parameters are inside this variable name. Is it possible to group into one name?

dt = open("---------");

family_device = Data Table("--------") << Summary (Group(:Family Device), Freq("None"), Weight("None"));
parameter = Data Table("---------") << Summary(
	Group(
		:Name( "I_P2A .6/.045 Avg @ ET" ),
		:Name( "I_N2A .3/.045 Avg @ ET" ),
		:Name( "I_P2G_G_0.6/0.06 @ ET" ),
		:Name( "I_P2HG_0.6/0.06 @ ET" )
	),
	Freq( "None" ),
	Weight( "None" )
);

For(ifamily_device = 1, ifamily_device <= NRows(family_devices), ifamily_device++,
   thisFamily_Device = family_devices : Family Device[ifamily_device];
	For(iparameter = 1, iparameter <= Nrows(parameters), iparameter++,
	thisParameter = parameters: (column name in dataset-how i convert all these 4 parameters into one group name?)[iparameter];
	Group(
		:Name( "I_P2A .6/.045 Avg @ ET" ),
		:Name( "I_N2A .3/.045 Avg @ ET" ),
		:Name( "I_P2G_G_0.6/0.06 Avg @ ET" ),
		:Name( "I_P2HG_0.6/0.06 Avg @ ET" )
	)
);

);

Thanks.

6 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

The errors in your code are symptoms of running too many steps in the JSL, so that you are getting confused as to what issues are causing what problems.  JSL provides some great things to help step through the code to see what the real issues are.  First of these is the abiltiy to highlight any section of code, and to run just the highlighted code.  And the abiltiy to just hover over a variable and to see what the last value for it is.  A more formal environment is to use the JSL Debugger, which will let you step line by line through your code to validate the logic and calculations.

Below is an evaluation of the code you supplied.  What you will see is that the errors in the code are coming from just not being careful enough with the variable names.

// This line of code has nothing to do with the script, so I have commented it out
//dt = open("---------");

// For testing purposes,a data table needs to be opened and setup with the columns used in the script
// Open the Big Class data table
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
// Now modify the data table to make it look like the script wants
// Delete the "name" column
dt << delete columns( "name" );
// The "sex" column will become the "Family Device" column
dt:sex << set name( "Family Device" );
// The "age", "weight", and "height" columns will be changed to three of the other columns required
dt:age << set name( "I_P2A .6/.045 Avg @ ET" );
dt:height << set name( "I_N2A .3/.045 Avg @ ET" );
dt:weight << set name( "I_P2G_G_0.6/0.06 @ ET" );
// Create the final column as a simple formula column
dt << New Column( "I_P2HG_0.6/0.06 @ ET", formula( Random Normal() ) );
// Now just remove the formula to make the values static(just a simple step to make the table clea)n
dt:Name( "I_P2HG_0.6/0.06 @ ET" ) << delete property( "Formula" );
// The sample data table is complete

// Now run the script

// The creation of the first summary data table....only the data table's name was substituted
// The summary works without error
family_device = Data Table( "Big Class" ) << Summary( Group( :Family Device ), Freq( "None" ), Weight( "None" ) );

// The creation of the second summary data table....once again only the data table name was changed
// There is no issue with the "@" being in the column names
// The summary works without error
parameter = Data Table( "Big Class" ) << Summary(
	Group( :Name( "I_P2A .6/.045 Avg @ ET" ), :Name( "I_N2A .3/.045 Avg @ ET" ), :Name( "I_P2G_G_0.6/0.06 @ ET" ), :Name( "I_P2HG_0.6/0.06 @ ET" ) ),
	Freq( "None" ),
	Weight( "None" )
);

// There are issues here.  The first one is that in the "NRows()" function, a variable by the
// name of "family_devices" is used, and there is not a variable by that name.  The name of 
// the variable is "family_device". When this code is run, that error is clearly listed in the Log
//For(ifamily_device = 1, ifamily_device <= NRows(family_devices), ifamily_device++,
For( ifamily_device = 1, ifamily_device <= N Rows( family_device ), ifamily_device++, 
   // Once again the reference to "family_device"  is made
	//thisFamily_Device = family_devices : Family Device[ifamily_device];
	thisFamily_Device = family_device:Family Device[ifamily_device];
   // For a third time, an invalid variable name has been specified.  In this case, "Parameters"
	// instead of "parameter"
	//For(iparameter = 1, iparameter <= Nrows(parameters), iparameter++,
	For( iparameter = 1, iparameter <= N Rows( parameter ), iparameter++, 
	// I am a bit confused on this one.  First off, "parameters" instead of "parameter" is used, however
	// the grouping question could be interpreted a couple of ways, so what I have done is to just
	// concatenate the columns together
/*thisParameter = parameters: (column name in dataset-how i convert all these 4 parameters into one group name?)[iparameter];
	Group(
		:Name( "I_P2A .6/.045 Avg @ ET" ),
		:Name( "I_N2A .3/.045 Avg @ ET" ),
		:Name( "I_P2G_G_0.6/0.06 Avg @ ET" ),
		:Name( "I_P2HG_0.6/0.06 Avg @ ET" )
	)*/
		thisParameter = Char( parameter:Name( "I_P2A .6/.045 Avg @ ET" )[iparameter] ) || Char( parameter:Name( "I_N2A .3/.045 Avg @ ET" )[iparameter] ) ||
		Char( parameter:Name( "I_P2G_G_0.6/0.06 @ ET" )[iparameter] ) || Char( parameter:Name( "I_P2HG_0.6/0.06 @ ET" )[iparameter] );
		show(thisFamily_Device, thisParameter );
	);
);
Jim
blue1994

Contributor

Joined:

Feb 27, 2017

One question from me:
According to your code, why we need to set the column name(rename the column)? Because in my case, the name of the column such as: (I_P2A .6/.045 Avg @ ET, I_N2A .3/.045 Avg @ ET, I_P2G_G_0.6/0.06 Avg@ET, I_P2HG_0.6/0.06 Avg @ ET-I still need it as my column name),my problem is how to group 4 different columns name to became one name in order for me to easy declare at the below code.
Because at last, I need to do the summarize based on family device and the parameters(4 different column name)
Thanks.
txnelson

Super User

Joined:

Jun 22, 2012

It seems that I don't understand what you want.  Maybe someone has better insight that I do.

Jim
blue1994

Contributor

Joined:

Feb 27, 2017

Sorry for not explain clearly what i want to do.
Actually what i want to do is, I want do the summarize based on the product type, for example: Now i have product a, b, c, d, e and each of the product has it own parameter list,eg:I_P2A .6/.045 Avg @ ET, I_N2A .3/.045 Avg @ ET, I_P2G_G_0.6/0.06 Avg@ET, I_P2HG_0.6/0.06 Avg @ ET etc. So now i want do filter or maybe using select matching cell to do out the summarization of product a use I_P2A .6/.045 Avg @ ET, product b use I_N2A .3/.045 Avg @ ET and etc. and each of the product has more than one parameters. Because after that i need based on the result to do out the charts. then my data is quite a lot, so i need to subset the data before do out the variability charts.And now my condition is i don't know how to do the script out to make the summarize that i explain. And i also cannot hard code also.
So, can you give me some of the suggestion?
thanks
blue1994

Contributor

Joined:

Feb 27, 2017

I think i use the picture maybe better.

Let say now i have S_GX, and it use parameters I_P2A GSVT .6/.045 Avg and I_N2A GSVT .3/.045 Avg. But now i need to summarize from my dataset, which meant here I need summarize S_GX will use two parameters which are I _P2A GSVT .6/.045 Avg and I_N2A GSVT .3/.045 Avg.etc...
Thanks

blue1994

Contributor

Joined:

Feb 27, 2017

photo 1.png