Just as you send data table messages to a data table reference, you can send column messages to a reference to a data column object. The Column function returns a data column reference. Its argument is either a name in quotation marks, something that evaluates to a name in quotation marks, or a number.
Column( "age" ); // a reference to the age column
col = Column( 2 ); // assign a reference to the second column
Note: You can also use the syntax :Name( "Profits ($M)" ) to evaluate to a name that contains special characters.
This book uses col to represent data column references. To see the messages that you can send to data column objects, refer to the Scripting Index (Help > Objects > Data Tables > Column Scripting). Alternatively, you can use the Show Properties() command, as follows:
Show Properties( col );
Sending messages to columns is comparable to sending messages to data tables. Either state the object, a double-angle operator <<, and then the message with its arguments in parentheses, or use the Send() function with the object and then the message. In some cases the messages themselves need no arguments, so the trailing parentheses are optional.
col << message( arg, arg2, ... );
Send( col, message(arg, arg2, ... ) );
col << message << message2 << ...
col << {message, message2, ...};
Tip: To delete a column, you must send the message to a data table reference, because objects cannot delete themselves, only their containers can delete them.
x = col[irow] // specific row
x = col[] // current row
col[irow] = 2; // as an l-value for assignment
dt << Select Where( col[]<14 ); // in a WHERE clause
dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
dt << Run Script( "Set Age Value Labels" );
x = Column( dt, "age", formatted )[1];
Show( x );
y = Column( dt, "age" )[1];
Show( y );
The log shows the formatted value for x, which is Twelve, and the actual data value for y, which is 12.