Subscribe Bookmark RSS Feed

Column name as variables

shasha

Community Member

Joined:

Dec 13, 2013

Hi there,

I have a question related to the column name convention.

For example, I have a table contains the ages of students from several grades.

age_grade1age_grade2age_grade3age_grade4age_grade5age_grade6age_grade7

I like to define a parameter, so I can use "for" loop to do some data processing.

1: only select the non-empty rows.

Parameter = "age_grade1" ;

dtRaw << Select Where( Is Missing( Parameter ) );

however, it won't do anything.

2. select students age in some range.

Parameter = "age_grade1";

dtRaw = select where (Parameter > 7);

it is not working either.

Please help me figure this out. What is the right syntax for the column name?

Thanks,

Shasha

1 REPLY
pmroz

Super User

Joined:

Jun 23, 2011

You need to supply a column reference in this context.  Also don't use parameter as a variable name - that's a JSL function.  If the word(s) turn blue in the editor then it means that it's a function.

This code works.  Note the use of as column for the column reference.

dtraw = current data table();

col_name = "age_grade1" ;

dtRaw << Select Where( Is Missing( as column(dtraw, col_name) ) );

dtRaw << select where (as column(dtraw, col_name) > 7);