cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
snapnpop
Level II

Stack column using table variable list

I would like to stack a list of columns based on a table variable, but I'm having trouble figuring out how to format the variable and the script

 

//this is my table variable -- I've called it myList
{"colName1", "colName2"}
//this is my script
dt = Current Data Table();
dt << Stack(
	columns(myList),
	Output Table( "New Table" )
);

I have a table with column names colName1, colName2, colName3...

And I would like to be able to stack only certain columns based on a table variable list. I've been able to do this by grouping columns then stacking the whole group, but I've run into situations where I may want to stack a subset of a group of columns, hence this attempt.

 

The list and script above gives me the error: "Column not found in access or evaluation of bad argument"

I've also tried changing the command to

columns(eval(myList))

but that gives me the same error 

1 ACCEPTED SOLUTION

Accepted Solutions
snapnpop
Level II

Re: Stack column using table variable list

Taking a hint from this thread, I figured out that using the Parse() command works for this.

 

Table variable myList formatted as such:

{"colName1","colName2"}

and script looks like this:

dt = Current Data Table();
dt << Stack
	( columns( Parse(myList) ), 
	Output Table( "Stacked Data" )
	);

View solution in original post

5 REPLIES 5
uday_guntupalli
Level VIII

Re: Stack column using table variable list

@snapnpop , 
      Shouldn't your table variable look like this ? 

      {"Column1", "Column2"} vs {"Column1, Column2"} ?

Best
Uday
snapnpop
Level II

Re: Stack column using table variable list

@uday_guntupalli
I've fixed my original post. My table variable was as you typed out.
I had also tried:
("colName1","colName1")
Both with the same errors
gianpaolo
Level IV

Re: Stack column using table variable list

hello,

you can try with this code

 

 

 

dt = current data table();

// column dialog editor
cd = Column Dialog(
Var = collist( " select columns >>", MinCol( 1 ) ), Hlist( "" ), );
collist= cd["Var"];

//stack operation
dt_stack = dt << Stack(
      columns( collist ), Output Table( "STacked" ),
);

 

Gianpaolo Polsinelli
snapnpop
Level II

Re: Stack column using table variable list

@gianpalo: the code you've posted allows me to manually select columns to stack each time I run the script.

My goal is to have a table variable with a list of column names to stack, then run a script that utilizes that variable.
The intent is to be able to edit the variable to add/remove columns to be stacked, as the dataset expands/contracts.
snapnpop
Level II

Re: Stack column using table variable list

Taking a hint from this thread, I figured out that using the Parse() command works for this.

 

Table variable myList formatted as such:

{"colName1","colName2"}

and script looks like this:

dt = Current Data Table();
dt << Stack
	( columns( Parse(myList) ), 
	Output Table( "Stacked Data" )
	);