Hello, I wanted to check if anyone has a solution for concatenating 3 columns with the labels of those columns rather than the values?
Thanks
Ritesh
Do you want the final column to have values or labels (or both)? One option I think could be to create associative array of each of those columns and then use the column value as key to get correct value and concatenate those.
Do you want to create a new column with the name being the other 3 column names concantenated to each other? Like this:
New Table( "Untitled 3", Add Rows( 0 ), Compress File When Saved( 1 ), New Column( "a", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ), New Column( "b", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ), New Column( "c", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ) ); NewColumnName = (Column(1)<<get name) || "-" || (Column(2)<<get name) || "-" || (Column(3)<<get name); New Column( NewColumnName, Numeric, "Continuous", Format( "Best", 12 ) );
following @jthi's idea, it could be something like this:
Names Default to Here(1); dt = Open( "$SAMPLE_DATA/Big Class.jmp" ); :age << Value Labels( {12 = "very young",13 = "young",14= "mid", 15 = "elder", 16 = "old",17 = "eldest"} ); Mylabels= arg(:age << get value labels,1); splitList=Transform Each({pair},MyLabels,EvalList({Arg(pair,1),Arg(pair,2)})); ageLabels=Associative Array(splitList); New column("new",Character, Set Each Value(:sex ||"_"|| ageLabels[:age]))
Alternatively, you could use Recode to get a column with the value labels - and then use this column.
but I fear, Recode doesn't have an option
Recode Column(columnname, <STRONG>Replace values with value labels</STRONG>, ...)
so, if you want to automate the process, you have to retrieve the label replacement rule like in the example above and paste it into the Recode Column expression:
dt << Recode Column( dt:age, Map Value( _rcOrig, {12, "very young", 13, "young", 14, "mid", 15, "elder", 16, "old", 17,"eldest"}, Unmatched( _rcNow ) ...