cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
gueriniere
Level I

Simple start for script

Hi

I am a bit embarrased that I get stuck on this simple task.

 

It is a simple task:

I have 2 data-tables (dt-1 and dt-2). I want to step through the first and for each row compare a value with a value in the second table, starting with first row in that table. If it is close enough I will collect a value from that dt-2 and save in a field in dt-1, put a special marker in a field in dt-2 so I know that row is taken and step to next row i dt-1, if it is not close enough I will step to next row in dt-2.

 

The programming is simple enough:

for(i=1 to i > row_count(dt-1), dt-1 (row-number = i), 
  for (j=1 to j>row_count(dt-2), dt-2 (row-number = j,
    if(dt-2(col-x) == dt1(col-y), dt_2(col-z=1; dt1(col-z)=dt2(col-a); i++; j=0, j++)
)

 

My questions:

What is the command in jsl to get the row-count of a dt?

What is the command in jsl to go to a specific row in a dt?

What is the command in jsl to retrieve the value from a specific column in a specific row?

What is the command in jsl to write data to a specific field in a specific row of a specific dt?

 

When I try to go through the instructions and manuals I get stuck in al discussions on how to create loops and simple ordinary programming but I cant find these references to dt, fields and rows. I'm probably blind but please help me where to look!

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Simple start for script

What is the command in jsl to get the row-count of a dt?

num_rows = nrows(dt);

What is the command in jsl to go to a specific row in a dt?

You don't go to a specific row - just reference the row number with brackets.  See your next question.

 

What is the command in jsl to retrieve the value from a specific column in a specific row?  Assuming your specific column is called specific_column:

one_value = dt:specific_column[i];

What is the command in jsl to write data to a specific field in a specific row of a specific dt?

dt:specific_column[i] = new_value;

View solution in original post

3 REPLIES 3
pmroz
Super User

Re: Simple start for script

What is the command in jsl to get the row-count of a dt?

num_rows = nrows(dt);

What is the command in jsl to go to a specific row in a dt?

You don't go to a specific row - just reference the row number with brackets.  See your next question.

 

What is the command in jsl to retrieve the value from a specific column in a specific row?  Assuming your specific column is called specific_column:

one_value = dt:specific_column[i];

What is the command in jsl to write data to a specific field in a specific row of a specific dt?

dt:specific_column[i] = new_value;
jthi
Super User

Re: Simple start for script

There is at least one other option for accessing row BUT I WOULD ALWAYS prefer the method @pmroz showed. I have used this mostly for debugging and not updating values in the datatable

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

Row() = 10;
:height = 11;

 

Check out also this post Data table subscripting 

 

-Jarmo
gueriniere
Level I

Re: Simple start for script

Tnx!! I knew it was simple but one can die searching for simple things!