cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
csoon1
Level III

How to Add Value Labels to a Column through JSL

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

Re: How to Add Value Labels to a Column through JSL

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

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How to Add Value Labels to a Column through JSL

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
Level III

Re: How to Add Value Labels to a Column through JSL

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