cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
DavidLeber
Level III

selectWhere on column attributes

I'm trying to select all columns which have the attribute "Units", and where the "Units" attribute has a value of "kg/hr". Is there some way to do a clean selectWhere, or do I need to iterate through each column to collect them?

1 ACCEPTED SOLUTION

Accepted Solutions
jerry_cooper
Staff (Retired)

Re: selectWhere on column attributes

Selecting columns with specific properties, such as "Units", can be done without JSL from the Cols->Columns Viewer menu by clicking on the "Find Columns with Properties" button and then selecting the "Units" check box. This will return a table with a 'Yes' or 'No' for the "Units" property. Sorting this table by right-clicking and selecting "Sort by column..." and then selecting "Units" will make it easy to select all columns with a "units" property. 

 

However, to select a specific unit, such as "kg/hr", would require iterating through your columns as you guessed. This would only take a few lines of JSL, something like:

Names Default To Here( 1 );
dt = Current Data Table();

For( i = 1, i <= N Cols( dt ), i++,
	If( Column( i ) << Get Property( "Units" ) == "kg/hr",
		Column( i ) << set selected
	)
);

Hope this helps.

View solution in original post

3 REPLIES 3
cwillden
Super User (Alumni)

Re: selectWhere on column attributes

As far as I know, there is no existing function that would spare you from iterating through your columns and checking them individually.  You could subset the columns you need to look at by getting a list of all numeric columns (e.g. numeric_cols = dt << Get Column Names(Numeric, Continuous)).  Unless you have a ridiculous number of columns, that probably won't make a noticeable difference in reducing compute time to execute that task.  Luckily, it's not very hard to do.

-- Cameron Willden
jerry_cooper
Staff (Retired)

Re: selectWhere on column attributes

Selecting columns with specific properties, such as "Units", can be done without JSL from the Cols->Columns Viewer menu by clicking on the "Find Columns with Properties" button and then selecting the "Units" check box. This will return a table with a 'Yes' or 'No' for the "Units" property. Sorting this table by right-clicking and selecting "Sort by column..." and then selecting "Units" will make it easy to select all columns with a "units" property. 

 

However, to select a specific unit, such as "kg/hr", would require iterating through your columns as you guessed. This would only take a few lines of JSL, something like:

Names Default To Here( 1 );
dt = Current Data Table();

For( i = 1, i <= N Cols( dt ), i++,
	If( Column( i ) << Get Property( "Units" ) == "kg/hr",
		Column( i ) << set selected
	)
);

Hope this helps.

GianpaoloP
Level I

Re: selectWhere on column attributes

Hi,

i create for my columns a  property called METADATA with info TEST

when i tried to select this columns the script doesn't show error, but the columns are not selected

can you help me?

 
For( i = 1, i <= N Cols( dt ), i++,
If( Column( i ) << Get Property( "METADATA" ) == "TEST",
Column( i ) << set selected (1),
)
 
thanks in advance
Gianpaolo
);