<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating a Stack script with Varying Column Names in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Creating-a-Stack-script-with-Varying-Column-Names/m-p/221239#M44158</link>
    <description>&lt;P&gt;Hi JMP Community,&lt;/P&gt;&lt;P&gt;I have a list of column headers (17 capture probes) and depending on the data, a particular data set may have any number of those 17 capture probes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a script where the stack function will stack columns that exist in the data set and ignore any other columns that are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I pulled the source script for one particular data set and tried to place an if() statement with a loop in order to try and accomplish this, but it's still not working because certain columns were not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've included the script that I have now.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
text_col_list = 
	{"SP1_A","SP12_B","SP35_A","SP37_A","SP5_A","SP7_A","SP2_A","SP39_A","SP38_A","SP41_A","SP40_A","SP42_A","SP3_A","SP4_A","SP6_A","SP10_A","SP11_A"};
jmp_col_list = 
	{"cSCR1","CP 34","CP 24 v.6.3","CP 34 v.1","CP 24 v.1","CP 44 v.1","CP 24","CP24 v.14
","CP24 v.13","CP24 v.16","CP24 v.15","CP24 v.17","CP 26","CP 44","CP 24 v.10","CP 32","CP 33"};

col_name_list = dt &amp;lt;&amp;lt; get column names(string);

for (i = 1, i &amp;lt;= nitems(text_col_list), i++,

    if (contains(col_name_list, text_col_list[i]),

        column(dt, text_col_list[i]) &amp;lt;&amp;lt; set name(jmp_col_list[i]);

    );
);

dt = Current Data Table();
jmp_col_list = 
	{"cSCR1","CP 34","CP 24 v.6.3","CP 34 v.1","CP 24 v.1","CP 44 v.1","CP 24","CP24 v.14
","CP24 v.13","CP24 v.16","CP24 v.15","CP24 v.17","CP 26","CP 44","CP 24 v.10","CP 32","CP 33"};

col_name_list = dt &amp;lt;&amp;lt; get column names(string);
 
for (i = 1, i &amp;lt;= nitems(jmp_col_list), i++,

	if (contains(col_name_list, jmp_col_list[i]), 
		&amp;lt;&amp;lt; Stack(columns(jmp_col_list),
		&amp;lt;&amp;lt;ignore errors(true)),
	Source Label Column( "Capture Probes" ),
	Stacked Data Column( "Intensity" ),
	Name( "Non-stacked columns" )(Keep(
		:Filename,
		:Condition,
		:Rep #,
		:Name( "Time (s)" ),
		:Name( "Date/Time" ),
		:Cartridge #
	))
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Aug 2019 23:49:35 GMT</pubDate>
    <dc:creator>khuynh</dc:creator>
    <dc:date>2019-08-09T23:49:35Z</dc:date>
    <item>
      <title>Creating a Stack script with Varying Column Names</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-a-Stack-script-with-Varying-Column-Names/m-p/221239#M44158</link>
      <description>&lt;P&gt;Hi JMP Community,&lt;/P&gt;&lt;P&gt;I have a list of column headers (17 capture probes) and depending on the data, a particular data set may have any number of those 17 capture probes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a script where the stack function will stack columns that exist in the data set and ignore any other columns that are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I pulled the source script for one particular data set and tried to place an if() statement with a loop in order to try and accomplish this, but it's still not working because certain columns were not found.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've included the script that I have now.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
text_col_list = 
	{"SP1_A","SP12_B","SP35_A","SP37_A","SP5_A","SP7_A","SP2_A","SP39_A","SP38_A","SP41_A","SP40_A","SP42_A","SP3_A","SP4_A","SP6_A","SP10_A","SP11_A"};
jmp_col_list = 
	{"cSCR1","CP 34","CP 24 v.6.3","CP 34 v.1","CP 24 v.1","CP 44 v.1","CP 24","CP24 v.14
","CP24 v.13","CP24 v.16","CP24 v.15","CP24 v.17","CP 26","CP 44","CP 24 v.10","CP 32","CP 33"};

col_name_list = dt &amp;lt;&amp;lt; get column names(string);

for (i = 1, i &amp;lt;= nitems(text_col_list), i++,

    if (contains(col_name_list, text_col_list[i]),

        column(dt, text_col_list[i]) &amp;lt;&amp;lt; set name(jmp_col_list[i]);

    );
);

dt = Current Data Table();
jmp_col_list = 
	{"cSCR1","CP 34","CP 24 v.6.3","CP 34 v.1","CP 24 v.1","CP 44 v.1","CP 24","CP24 v.14
","CP24 v.13","CP24 v.16","CP24 v.15","CP24 v.17","CP 26","CP 44","CP 24 v.10","CP 32","CP 33"};

col_name_list = dt &amp;lt;&amp;lt; get column names(string);
 
for (i = 1, i &amp;lt;= nitems(jmp_col_list), i++,

	if (contains(col_name_list, jmp_col_list[i]), 
		&amp;lt;&amp;lt; Stack(columns(jmp_col_list),
		&amp;lt;&amp;lt;ignore errors(true)),
	Source Label Column( "Capture Probes" ),
	Stacked Data Column( "Intensity" ),
	Name( "Non-stacked columns" )(Keep(
		:Filename,
		:Condition,
		:Rep #,
		:Name( "Time (s)" ),
		:Name( "Date/Time" ),
		:Cartridge #
	))
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Aug 2019 23:49:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-a-Stack-script-with-Varying-Column-Names/m-p/221239#M44158</guid>
      <dc:creator>khuynh</dc:creator>
      <dc:date>2019-08-09T23:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Stack script with Varying Column Names</title>
      <link>https://community.jmp.com/t5/Discussions/Creating-a-Stack-script-with-Varying-Column-Names/m-p/221267#M44162</link>
      <description>&lt;P&gt;If my interpretation of the various lists in your script is correct, and what I think you are attempting to do, I believe the following script will do what you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

// List of possible columns to be stacked
jmp_col_list = {"cSCR1", "CP 34", "CP 24 v.6.3", "CP 34 v.1", "CP 24 v.1", "CP 44 v.1",
"CP 24", "CP24 v.14", "CP24 v.13", "CP24 v.16", "CP24 v.15", "CP24 v.17", "CP 26",
"CP 44", "CP 24 v.10", "CP 32", "CP 33"};

// List name of the list of columns found in the current data table
found_List = {};

// Columns in the data table
col_name_list = dt &amp;lt;&amp;lt; get column names( string );

// Loop through the columns in the data table, and if found in the
// jmp_col_list, then place them into the found_List

For( i = 1, i &amp;lt;= N Items( col_name_list ), i++,
	If( Contains( jmp_col_list, col_name_list[i] ),
		Insert Into( found_List, col_name_list[i] )
	)
);

// Stack the columns found
dtStacked = dt &amp;lt;&amp;lt; Stack(
	columns( Eval( found_list ) ),
	Source Label Column( "Capture Probes" ),
	Stacked Data Column( "Intensity" ),
	Name( "Non-stacked columns" )(Keep(
		:Filename,
		:Condition,
		:Rep #,
		:Name( "Time (s)" ),
		:Name( "Date/Time" ),
		:Cartridge #
	))
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Aug 2019 01:43:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Creating-a-Stack-script-with-Varying-Column-Names/m-p/221267#M44162</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-08-10T01:43:27Z</dc:date>
    </item>
  </channel>
</rss>

