cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
natalie_
Level V

How can I find the row and column of a value within a data table?

Hi all,

I need to find the column and row number of a particular value within a data table.   I know how to search for a value within a particular column (ie., row = dt1 << get rows where(:Device == "Device");) , which returns the row number, but what if I don't know what row it will be in?

Is it possible to do this in JMP?  I see how to do it from going to edit then search, but is there a way to do this in JSL?

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: How can I find the row and column of a value within a data table?

If you're looking for text, then this example may be helpful:

dt = open("$sample_data\Bands Data.jmp");

char_cols = dt << get column names(Character, string);

search_string = "E310";

for (i = 1, i <= nitems(char_cols), i++,

    match_rows = dt << get rows where(as column(dt, char_cols[i]) == search_string);

    if (nrows(match_rows) > 0,

        print("Column: [" || char_cols[i] || "] Rows: " || char(match_rows));

    );

);

View solution in original post

2 REPLIES 2
pmroz
Super User

Re: How can I find the row and column of a value within a data table?

If you're looking for text, then this example may be helpful:

dt = open("$sample_data\Bands Data.jmp");

char_cols = dt << get column names(Character, string);

search_string = "E310";

for (i = 1, i <= nitems(char_cols), i++,

    match_rows = dt << get rows where(as column(dt, char_cols[i]) == search_string);

    if (nrows(match_rows) > 0,

        print("Column: [" || char_cols[i] || "] Rows: " || char(match_rows));

    );

);

natalie_
Level V

Re: How can I find the row and column of a value within a data table?

Thank you, your examples are always great!

I know that the value can only happen once in the file, so I made a while loop instead so that it would not continue to check the other columns for it.

file = Pick File();

dt = Open (file);

for(i=1, i<=ncols(dt), i++,

  column(dt,i) << data type(Character);

  column(dt,i) << set modeling type(continuous);

);

nCols = dt << Get Column Names ("Character");

found =0;

search_string = "Vtlin";

i=1;

While (found == 0,

  match_rows = dt << get rows where(as column(dt, nCols)==search_string);

  if(nrows(match_rows) > 0, found = 1, i++);

  if(i==nCols, found =1, );

);

vtlinCol = i;