cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
ClaireR
Level II

JSL Script using loops and summary

Need any suggestion on how to make this loop work: itt keeps hiccuping at the line with Group( Box(i) ) and i thought it was an issue with number or brackets / incorrect column names. but adjust these did not help

 

 

For( j = 1, j < 3, j++, 
    nrj j = dt1 << Summary(
        Group( Box( i ) ),
        Freq( "None" ),
        Weight( "None" ),
        Link to original data table( 0 ),
        output table name( "Sum " || Char( j ) )
    )
);

 

5 REPLIES 5
txnelson
Super User

Re: JSL Script using loops and summary

// I am assuming that your syntax of
//    nrj j = dt1 << Summary(
// was an attempt to create a pointer to each new data table
// being created in the Loop, one for each column in the list
// of columns called "Box"
// To do that, one needs to create a new List variable, and then
// populate the list by inserting the new data table reference
// by using an "Insert Into()" on each loop

// Create a list variable to hold the data table references
mrj = {};

For( j = 1, j < 3, j++, 

	newDT = dt1 << Summary(
		// Your reference to the list variable called "Box"
		//      Group( Box(i) ),
		// incorrect for 2 reasons.  1. When referencing a
		// subscript, it is done using square brackets [ ],
		// 2. the index variable you are specifying is "i",
		// while the index variable for your For() loop is
		// a the variable "j"
		Group( Box[j] ),
		Freq( "None" ),
		Weight( "None" ),
		Link to original data table( 0 ),
		output table name( "Sum " || Char( j ) )
	);
	Insert Into( mrj, newDT );
);
Jim
ClaireR
Level II

Re: JSL Script using loops and summary

Thank you Jim.

 

I understand the need to add the list variable & the typo. however when i updated the code- & ran it , i get this error. My Column names are "Box 1" . "Box 2" etc. 

 

However i did try changing the column names to Box1 , Box 2 and Box3 etc , and got the same error. any suggestions? 

 

 

2020-09-17_12-10-24.jpg

txnelson
Super User

Re: JSL Script using loops and summary

I assumed that Box was referencing a memory variable called Box which is a list, and contains several elements, each one being the name of a variable. If this isn't it, what is Box?
Jim
ClaireR
Level II

Re: JSL Script using loops and summary

MMMM i am not sure...my script skills are subpar. Here is my whole code. It runs okay upto the loop section with the summary step.

 

t1 = Open( "C:\Users\ClaireR\Desktop\Example\ExampleABC.jmp" );

For( i = 1, i <= 5, i++, 

    dt1 << New Column( "Scenario", Numeric, "Continuous", Formula( :Place ID - i ) );

    dt1 << New Column( "Box",
        Character,
        "Nominal",
        Formula(
            If( (:Place ID - i) <= 200,
                "Ground",
                If( (:Place ID - i) <= 250,
                    "Drop 1",
                    If( (:Place ID - i) <= 400,
                        "Ground",
                        If( (:Place ID - i) <= 450,
                            "Drop 2",
                            If( (:Place ID - i) <= 600,
                                "Ground",
                                If( (:Place ID - i) <= 650,
                                    "Drop 3",
                                    If( (:Place ID - i) <= 800,
                                        "Ground",
                                        If( (:Place ID - i) <= 850,
                                            "Drop 4",
                                            "Ground"
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )

    );

    dt1 << New Column( "ActualLoc",
        Character,
        "Nominal",
        Formula(
            If( (:Place ID - i) <= 200,
                "Ground",
                If( (:Place ID - i) <= 250,
                    :Place ID 2,
                    If( (:Place ID - i) <= 400,
                        "Ground",
                        If( (:Place ID - i) <= 450,
                            :Place ID 2,
                            If( (:Place ID - i) <= 600,
                                "Ground",
                                If( (:Place ID - i) <= 650,
                                    :Place ID 2,
                                    If( (:Place ID - i) <= 800,
                                        "Ground",
                                        If( (:Place ID - i) <= 850,
                                            :Place ID 2,
                                            "Ground"
                                        )
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )


    );

);

:Scenario << Set Name( "Scenario 1" );
:Box << Set Name( "Box 1" );
:ActualLoc << Set Name( "ActualLoc" );

 

mrj = {};

For( j = 1, j < 3, j++, 

    newDT = dt1 << Summary(
        Group( Box[j] ),
        Freq( "None" ),
        Weight( "None" ),
        Link to original data table( 0 ),
        output table name( "Sum " || Char( j ) )
    );
    Insert Into( mrj, newDT );
);

 

txnelson
Super User

Re: JSL Script using loops and summary

I created a data table with a column called Place ID.  I populated it with 100 random values that ranged from 1 to 850.

place1.PNG

I then ran the section of code that various  Box and ActualLoc and it created a data table that looks like this:

place2.PNG

I do not see the intent with performing these operations.

It appears to me(I could easily be wrong) that you do not have the understanding of some elements that you are using.  Within your first For() loop, you create the same columns of Scenario, Box and ActualLoc 5 times.  And since JMP will not allow a column have the same name, when you create Scenario, Box and ActualLoc during the first loop, those are the actual names it will use.  However, on loop 2, JMP will force the names to Scenario 2, Box 2 and ActualLoc 2.  Loops 3,4,and 5 repeat this behavior.  The formulas used are also a little confusing.  You are repeatedly using the specification of (:Place ID - i).  Since this is being used in a formula, which means that the formula will be applied to each row in the data table, and  the result of this calculation will be the value of the variable Place ID for the given row (i.e row 1 in my data table has the value 268) and it will subtract off the current value of i, which has the value of 1 on the first loop, 2 on the second loop, etc.  Thus the for row 1, the values range from 267 to 263.  I suspect you may be thinking that :Place ID -1 is referencing the column that comes before :Place ID.

 

Can you help me out, and clarify what you are attempting to do to your data table with the column Place ID in it?

Jim