cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
hogi
Level XIII

robust column reference

After a few minutes coding with JSL, users wonder about strange objects like :sex in 

 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

x = :sex

 

 

Expert users have some experience with such column references and use them all the time.
But what is :sex ? Is  dt:sex  more robust? Where do I find a documentation ?

Let's collect and share some insights.

my 5 cents:

15 REPLIES 15
hogi
Level XIII

Re: robust column reference

Take home message:

With the learning from 

myList2 = Eval List({Name Expr(As column(:name)),Name Expr(As column(:sex)),Name Expr(As column(:age))});

we can convert any list provided by JMP into a robust list of columns via

ColNames = dt << get column names;
colList = Transform Each({col}, ColNames, Name Expr(As Column (col)));

 

Byron_JMP
Staff

Re: robust column reference

my approach is much more simplistic. I'm careful to build my list of columns for the specific purpose I have in mind. Sometimes I have multiple lists of the columns in different formats.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
text = dt << Get Column Names();
quote = dt << Get Column Names( String );
colformat = dt << get column reference();
quote = dt << Get Column Names( String );
show(text, quote, colformat);

which returns:

text = {name, age, sex, height, weight};

quote = {"name", "age", "sex", "height", "weight"};

colformat = {Column("name"), Column("age"), Column("sex"), Column("height"), Column("weight")};

 

one of the three generally works, even if I have to resort to eval(parse())

JMP Systems Engineer, Health and Life Sciences (Pharma)
hogi
Level XIII

Re: robust column reference

Basically, I am with you. After taking some precaution, names are not very dangerous:

One can argue if it's clever to rename a column after creating a column list - and then to wonder/complain that the old name doesn't work anymore.

 

And when working with two tables, one has to ensure that the correct data table is the current data table().

 

Same with column names:
One can assume that JMP handles column names correctly -  even with capital letters and spaces. [find the link]
Or one can be cautious and follow some rules. (no collisions of names, variables and column names; caution with space, ...) and most of the day live safe without issues.

hogi
Level XIII

Re: robust column reference

Hi @Byron_JMP , to be picky ...


hogi_1-1758832329226.png

hogi_2-1758832336830.png

get column names() returns a list of  names ; )

hogi
Level XIII

Re: robust column reference

Important finding - I just edited one of the first posts!

 

I hope my thoughts are understandable - at least to some users like @Craige_Hales .
I guess, these users will also share my astonishment/enlightenment/joy and/or :help out by confirming that it's like this, provide an explanation, or make corrections.

Up to now I thought about As Column(col) as a way to retrieve the value of the current row - especially compared to Column(col) for "column access"  (you know, like in Column(col) << get name).

With the inverse implication:
Whenever I use :col for anything other than the "value of the current row",then when I want to replace it with a variable, then I don't have to use As column(),  I have to use the other one instead, namely Column(col).

 

[I must admit that I was also puzzled by the name:

As column() - for the function that does the inverse, get not the column, but the value of the current row? you are kidding?

another thought:
If As Column(col) works in such cases, then it's just because JMP corrects the error of the user automatically - or because of an esoteric effect that everybody uses but nobody explains - like in Name expr(As column(col))

So, I feel very comfortable now after finding out:  ....]

 

This interpretation must be wrong. It is triggered by an automatism in JMP which might follow the idea:

As column(col)gives access to the column.
If it it evaluated (Eval(As Column() ...))i, it converts to  column(col)[] aka column(col)[row()] which can be used to access the value of the current row. 
If it is not evaluated, but used in other functions, it gives access to the column.

 

Why do I think that it's like this?

 

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

row()=10;

Lag(:height);                           // 60
Show(lag(Column ("height"),1));         // Column("height") !!!
Show(lag(As Column ("height"),1));     // 60 !!!

Col Mean(:height);                             // 6255
Col Mean(:height, :age);                       // 60.285...
Show(Col Mean(Column ("height")));             // 62.55 (why does it work? another automatism because it is used so often?)
Try(Show(Col Mean(Column ("height"), :age)),Print(exception_msg)); //  !!!
Show(Col Mean(As Column ("height"), :age));    // 60.285...

[ triggered by https://community.jmp.com/t5/Discussions/Using-numeric-objects-in-a-column-equation/m-p/903939/highl... ]

hogi
Level XIII

Re: robust column reference

Based on this learning, I have a specific question:

 

Is there a comprehensive overview of

 

  1. which functions act in the spirit of
    Eval(:col), Where(:col=1) and  Type(:col) ?
    i.e. taking the column :col  and interpreting it as :col[row()] ?
    View more...
    rw = Row();
    Where( :age == Column( "age" )[rw] );
  2. , and which functions simply treat the column as a column - without "adding [row] for free"?
    like Col median(:col), Lag(:col,1)

 

Which group has the most members?

Recommended Articles