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

Combine columns which contain specific substring in their name

Hi,

 

I am trying to combine only the columns in Data table "dtPatList" which contain the substring "INIT" in their name, but it doesn't work.

I understand that the problem related to the parameter I bolded below. could someone advise for the right way?

 

Thanks!!

 

 

// get the dt cols names

nc = ncols(dtPatList);

 

// get the dt cols names

col_list = dtPatList << get column names(string);

for (i = nitems(col_list), i > 0, i--,

if (!contains(col_list[i], "INIT")), /// new ps columns

remove from(col_list, i);

)    

);

 

//Combine init cols 

dtPatList << Combine Columns(

delimiter( "_" ),

Columns(col_list),

Selected Columns are Indicator Columns( 0 ),

Column Name( "INIT_Chain" )

);

2 REPLIES 2
jthi
Super User

Re: Combine columns which contain specific substring in their name

Try adding Eval() inside Columns:

Columns(Eval(col_list))
-Jarmo
txnelson
Super User

Re: Combine columns which contain specific substring in their name

You need to place an eval() function around the col_list, to have it expanded in the function Combine Columns execution.

// get the dt cols names
dtPatlist = current data table();
nc = N Cols( dtPatList );

 

// get the dt cols names

col_list = dtPatList << get column names( string,character );

For( i = N Items( col_list ), i > 0, i--, 

	If( !Contains( col_list[i], "INIT" ), /// new ps columns

		Remove From( col_list, i );

	)    

);

 

//Combine init cols 

dtPatList << Combine Columns(

delimiter( "_" ),

Columns(eval(col_list)),

Selected Columns are Indicator Columns( 0 ),

Column Name( "INIT_Chain" )

);
Jim