Subscribe Bookmark RSS Feed

Column referencing: What is the difference between Column("Example") and :Name("Example")?

shaira

Contributor

Joined:

May 4, 2017

Dear all,

By googling examples, I kinda get the hang of when to use Column("Example") and :Name("Example"). When used in summary table and equality conditions, I use :Name("Example"). Meanwhile, I use Column("Example") when changing column properties.

 

However, I still fail to understand the difference between the two, concept-wise. Can anyone give insights to help me understand the difference between the two?

 

Thank you,

Shaira

1 ACCEPTED SOLUTION

Accepted Solutions
markbailey

Staff

Joined:

Jun 23, 2011

Solution

I believe, too, that Name() is not a JSL function but a directive to the JSL interpreter. It is meant to help the interpreter handle improper names when a user saves a script. (For example, click the red triangle at the top of a platform and select Save Script > To Data Table.) On the other hand, the Column() function is intended for us to obtain a valid column reference given a column index or proper name and optionally a data table reference.

I don't use the Name() directive in my scripts. That practice is a matter of personal choice and scripting style.

Learn it once, use it forever!
4 REPLIES
Byron_JMP

Staff

Joined:

Apr 26, 2012

There are lots of ways to reference a column. For Example:

Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Big Class.jmp" );
a = Column( 4 )[1] + Column( 4 )[2];
b = Column( 4 )[1] + :name( "height" )[2];
c = Column( 4 )[1] + Column( "height" )[2];
d = Column( 4 )[1] + :height[2];
Show( a, b, c, d );

:Age << Color Cells( "Red" );
Column( 4 ) << Color Cells( "blue" );
:name( "weight" ) << Color Cells( "green" );

:height << Set Property( "Units", inches );
column(5)<< set property( "Units", lbs);
:name("weight")<<get property ("Units");

Distribution(Continuous Distribution( Column( :height )));
Distribution(Continuous Distribution( Column( :name("weight") )));
Distribution(Continuous Distribution( Column( 5 )));
Distribution(Continuous Distribution( Column( "height" )));


how you reference a column depends on what you are trying to do, and what's convenient.

markbailey

Staff

Joined:

Jun 23, 2011

Solution

I believe, too, that Name() is not a JSL function but a directive to the JSL interpreter. It is meant to help the interpreter handle improper names when a user saves a script. (For example, click the red triangle at the top of a platform and select Save Script > To Data Table.) On the other hand, the Column() function is intended for us to obtain a valid column reference given a column index or proper name and optionally a data table reference.

I don't use the Name() directive in my scripts. That practice is a matter of personal choice and scripting style.

Learn it once, use it forever!
pmroz

Super User

Joined:

Jun 23, 2011

One other wrinkle to keep in mind.  Sometimes column("Column Name") doesn't work.  Instead you have to say AS Column("Column Name"). I've had to use this reference method for get rows where and with new column formulas. For example:

 

match_rows = rts_signal_detail_report_dt << get rows where(as column(rts_signal_detail_report_dt, one_col) == "Y");


xl_dt << new column("TMP_AER#VER", character, nominal, 
 formula(as column(xl_col1) || "#" || char(as column(xl_col2))));

I found this out by trial and error.  I.e. it didn't work using the regular column() reference, so I tried AS Column and it worked.

shaira

Contributor

Joined:

May 4, 2017

Thank you all for the input.

@pmrozNow, I am curious why some column references work, while others don't. But I'll keep this in mind. Thanks for sharing this.

 

Regards,

Shaira