Subscribe Bookmark RSS Feed

How to Add Value Labels to a Column through JSL

csoon1

Community Trekker

Joined:

Feb 9, 2016

On my main table (Table 1), I have a column called "Bin" which holds any number (corresponding to the column "Bin Number" entries on  another table which is Table 2). Now I want to assign Value Labels to this column "Bin" through script. The value labels would be coming from Table 2 with two columns: "Bin Number" and "Description". 

 

Hard-coding something like 

Column( dt, 1 ) << Add Column Properties( Value Labels( {"1" = "Cool", "2" = "Awesome", "3" = "Bad"} ), Use Value Labels( 1 ) );

is simple enough. However I am struggling with how to create the expression with the value labels being dynamic and formulated from whats on the other table. On the above code, "1, 2, 3,..." are entries for "Bin Number" while "Cool, Awesome, Bad,..." are entries for "Description" from Table 2.

 

I appreciate it if you can point me to some neat tricks. Thanks!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is one way to handle the issue.  It basically creates a string that contains the specific structure needed.  Then add it as an element into the list required to be used to add the Value Labels to the column.

Names Default To Here( 1 );
dt = New Table( "Untitled 36", Add Rows( 3 ), 
	New Column( "Column 1", Character, "Nominal", 
	Set Values( {"1", "2", "3"} ) ) );

NamesList = {"Cool", "Awsome", "Bad"};
	
ValuesList = Column( dt, 1 ) << get values;

NamesValuesList = {};

// Build the Value Labels List
For( i = 1, i <= N Items( NamesList ), i++,
	Insert Into( namesvalueslist, 
		Parse( "\!"" || ValuesList[i] || "\!" = \!"" || NamesList[i] || "\!"" ) )
);

// Create the Value Labels
Column( dt, 1 ) << set property( "Value Labels", Eval( NamesValuesList ) );
Jim
2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Solution

Here is one way to handle the issue.  It basically creates a string that contains the specific structure needed.  Then add it as an element into the list required to be used to add the Value Labels to the column.

Names Default To Here( 1 );
dt = New Table( "Untitled 36", Add Rows( 3 ), 
	New Column( "Column 1", Character, "Nominal", 
	Set Values( {"1", "2", "3"} ) ) );

NamesList = {"Cool", "Awsome", "Bad"};
	
ValuesList = Column( dt, 1 ) << get values;

NamesValuesList = {};

// Build the Value Labels List
For( i = 1, i <= N Items( NamesList ), i++,
	Insert Into( namesvalueslist, 
		Parse( "\!"" || ValuesList[i] || "\!" = \!"" || NamesList[i] || "\!"" ) )
);

// Create the Value Labels
Column( dt, 1 ) << set property( "Value Labels", Eval( NamesValuesList ) );
Jim
csoon1

Community Trekker

Joined:

Feb 9, 2016

Thank you very much it worked. Your response made it look so easy.