Subscribe Bookmark RSS Feed

Using a Variable as a Column Identifier

apeden

Community Trekker

Joined:

Jun 23, 2011

How do you use a variable as a column name identifier.

I have a column in table  A which contains names in text format of columns from table B. I want to extract one of the column names from table A and use this to identify a column from column B to do a selection on.

I can extract the column identifier from column A and store this in a variable however I can t get jmp to recognise this as a column name. I have tried using

Column(column_ID_variable)


However this doesnt work as it is looking for a string instead of a variable.I have also tried using Eval on the variable but again this doesnt work.

The code line I have tried is below where the variable colvar contains the column name as a text string

tableB<<select where column(colvar)=="F");

I  would appreciate any help on this.

Thanks

Allan

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

You need "as column", and also select where puts it's entire clause inside parentheses.

clist_dt = New Table( "Table 1",

    Add Rows( 3 ),

    New Column( "Column Names",

        Character,

        Nominal,

        Set Values( {"AAA", "BBB", "CCC"} )

    )

);

data_dt = New Table( "Table 2",

    Add Rows( 6 ),

    New Column( "AAA",

        Character,

        Nominal,

        Set Values( {"A", "B", "C", "D", "E", "F"} )

    ),

    New Column( "BBB",

        Character,

        Nominal,

        Set Values( {"F", "G", "H", "I", "J", "K"} )

    ),

    New Column( "CCC",

        Character,

        Nominal,

        Set Values( {"Z", "Y", "X", "F", "E", "F"} )

    )

);

for (i = 1, i <= nrows(clist_dt), i++,

    one_column = column(clist_dt, "Column Names")[i];

   

    data_dt << select where(as column(one_column) == "F");

   

    wait(3);

);

2 REPLIES
Solution

You need "as column", and also select where puts it's entire clause inside parentheses.

clist_dt = New Table( "Table 1",

    Add Rows( 3 ),

    New Column( "Column Names",

        Character,

        Nominal,

        Set Values( {"AAA", "BBB", "CCC"} )

    )

);

data_dt = New Table( "Table 2",

    Add Rows( 6 ),

    New Column( "AAA",

        Character,

        Nominal,

        Set Values( {"A", "B", "C", "D", "E", "F"} )

    ),

    New Column( "BBB",

        Character,

        Nominal,

        Set Values( {"F", "G", "H", "I", "J", "K"} )

    ),

    New Column( "CCC",

        Character,

        Nominal,

        Set Values( {"Z", "Y", "X", "F", "E", "F"} )

    )

);

for (i = 1, i <= nrows(clist_dt), i++,

    one_column = column(clist_dt, "Column Names")[i];

   

    data_dt << select where(as column(one_column) == "F");

   

    wait(3);

);

apeden

Community Trekker

Joined:

Jun 23, 2011

This worked a treat.

thanks for your help.

cheers

Allan