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
RosDima
Level II

Several Data Tables created in a same script

Hi All,

 

I am trying to create a second Data Table from a created first Data Table in a same script, is it possible?

 

Example:
dt_= Open(path_pst);

 

//First Data Table

start = New Table("W",
New Column("S"),
New Column("Z"),
New Column("X"),
New Column("Y"),
New Column("E"),
New Column("W"),
New Column("S"),
Add Rows(545)
);

 

//Some Calculations

for(i=1,i<=545,i++,
W:B[i] = ((dt_ - dt_*60)/8;
W:S[i] = dt_[i];
W:X[i] = dt_[i]/10000000;
W:Y[i] = dt_[i]/10000000;
W:E[i] = dt_[i];
W:W[i] = dt_[i];
W:S[i] = dt_[i];
);

 

//Creating a second Data Table

start = New Table("WIWM",
New Column("Si"),
New Column("Ba"),
New Column("X1"),
New Column("Y1"),
New Column("En"),
New Column("Wa"),
New Column("M"),
Add Rows(109)
);

 

//Calculation for second Data Tabe based on the first Data Table created

 

for (i=1, i<=109,i++,
WIWM:Ba[i] = (W:B[i+109]+W:B[i+218]+W:B[i+327]+W:B[i+436])/4;
WIWM:Si[i] = W:S[i];
WIWM:X1[i] = W:X[i];
WIWM:Y1[i] = W:Y[i];
WIWM:En[i] = W:E[i];
WIWM:Wa[i] = W:W[i];
);

 

After First Data Table comes as expected, second Data Table comes with expected rows numbers but blanked( for condition not run).

If I will saparate Script so in a first part I will perform the first calculation and save it and after I will run a second part on saved Data Table I will get my calculation done for second Data Table.

 

Thanks. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Several Data Tables created in a same script

Your script taught me something new.  I could not find any documentation of it, but your script shows that it works.....kind of.

In your code, you are referencing rows and columns in the data tables by

     data table name : column name[ row ]

So when you specify

     Start = New Table( "W", New Column( "S"), ..........

You reference the column "S" in row "5" as

     W:S[5]

and apparently that works.  However, later in your script, you attempt to use the same logic for the data table you name

     Start = New Table( "WIWM", New Column( "Si").........

and you try to reference back to your data table named W

     WIWM:SI[1] = W:S[1];

and that doesn't work.

The issue is, that the proper way to setup a data table namespace reference is to assign the namespace name by the use of an assignment statement, not the data table name.  My new learning is that apparently JMP will use the data table name as a name space until a new data table is created, and then it looses the data table name namespace link.

The bottom line is that your code will work fine if you change the line

     Start = New Table("W",

to

     W = New Table("W",

and

     Start = New Table("WIWM",

to

     WIWM = New Table("WIWM",

 

Finally, you open a file of some sort and reference it as

     dt_ = open(path_pst);

What is it you are opening?  I assume it is a matrix.  Could you please get back to me on this, so I can have a better understanding on what is really going on in your code.

Jim

View solution in original post

7 REPLIES 7
Craige_Hales
Super User

Re: Several Data Tables created in a same script

use the data table object returned by the NewTable function to tell which table a variable is in. The table's name is not used for the scoping of the variables. The third assignment uses all three tables. I named everything uniquely, but that isn't required with scoping.  dt3: , for example, sets the scope, or the places to look, for the variable that follows, z, in this example.

dt1 = New Table( "table name A", New Column( "x", values( [1 2 3] ) ) );
dt2 = New Table( "table name Squares", New Column( "y" ), addrows( 3 ) );
dt3 = New Table( "table name Cubes", New Column( "z" ), addrows( 3 ) );

For( i = 1, i <= N Rows( dt1 ), i++,
    dt2:y[i] = dt1:x[i] ^ 2;
    dt3:z[i] = dt1:x[i] * dt2:y[i];
);

small table of Cubessmall table of Cubes

Craige
txnelson
Super User

Re: Several Data Tables created in a same script

Your script taught me something new.  I could not find any documentation of it, but your script shows that it works.....kind of.

In your code, you are referencing rows and columns in the data tables by

     data table name : column name[ row ]

So when you specify

     Start = New Table( "W", New Column( "S"), ..........

You reference the column "S" in row "5" as

     W:S[5]

and apparently that works.  However, later in your script, you attempt to use the same logic for the data table you name

     Start = New Table( "WIWM", New Column( "Si").........

and you try to reference back to your data table named W

     WIWM:SI[1] = W:S[1];

and that doesn't work.

The issue is, that the proper way to setup a data table namespace reference is to assign the namespace name by the use of an assignment statement, not the data table name.  My new learning is that apparently JMP will use the data table name as a name space until a new data table is created, and then it looses the data table name namespace link.

The bottom line is that your code will work fine if you change the line

     Start = New Table("W",

to

     W = New Table("W",

and

     Start = New Table("WIWM",

to

     WIWM = New Table("WIWM",

 

Finally, you open a file of some sort and reference it as

     dt_ = open(path_pst);

What is it you are opening?  I assume it is a matrix.  Could you please get back to me on this, so I can have a better understanding on what is really going on in your code.

Jim
Craige_Hales
Super User

Re: Several Data Tables created in a same script

Thanks Jim.  I'm adding this to the list of things to investigate further...like you, I had no idea there was something like that.

Craige
RosDima
Level II

Re: Several Data Tables created in a same script

Hi,

 

Thank you for a quick replay. 

Yes, I am working with matrix, first one is n columns, and 545 rows (I can use col number function but it was for you to see the number)

From firts actual Data Table, I need filter and create a new Data Table - "first one" with 545 rows and matrix as well.

After that, I need to perform another calculations from "first one" and eventually get "second one" with 109 rows and also martix.

 

Thanks.

txnelson
Super User

Re: Several Data Tables created in a same script

Since you are working with matricies, I will then ask the question, why are you putting the data into a data table, and then treating the data table like it is a matrix holder?  All of the steps you are doing in your script could easily and more quickly done in open JSL using matricies.

Jim
RosDima
Level II

Re: Several Data Tables created in a same script

Can you give me an example?

Thanks

Craige_Hales
Super User

Re: Several Data Tables created in a same script