<?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 Re: Script for column stack by prefix for variable number of columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52925#M29953</link>
    <description>Thanks! If I wished to then recode the column (with a script) so that only the prefix remained i.e. so it read only S01, S02 etc., can this be done in a similar fashion to the stack?</description>
    <pubDate>Fri, 09 Mar 2018 16:27:44 GMT</pubDate>
    <dc:creator>nhun</dc:creator>
    <dc:date>2018-03-09T16:27:44Z</dc:date>
    <item>
      <title>Script for column stack by prefix for variable number of columns</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52800#M29910</link>
      <description>&lt;P&gt;I am trying to produce a general script that will import my data from excel as a data table, and then stack my columns based on the prefix of the column name. I wish for it to be applied to different datasets (not at the same time - just a general script that could apply for all) each with a different sample numbers (columns),&amp;nbsp;where each data column is listed as: S01 Vol Density (%), S02&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;Vol&amp;nbsp;Density (%), S03&amp;nbsp;Vol&amp;nbsp;Density (%) ... Sn Vol Density (where n = any integer).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am thinking the way to do this is by grouping the columns by the prefix and then stacking the group however I am unsure how to proceed with this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this made sense - still new to scripting so sorry if my question is not the clearest&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;N.B. Importing data is not an issue, just the stacking&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 16:11:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52800#M29910</guid>
      <dc:creator>nhun</dc:creator>
      <dc:date>2018-03-08T16:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Script for column stack by prefix for variable number of columns</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52818#M29914</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11242"&gt;@nhun&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Welcome to the community!&lt;/P&gt;&lt;P&gt;This is pretty easy to do in just a short amount of code.&amp;nbsp; Here's one way that loops through the column names and inserts the ones with the matching substrings into a list we can use with Stack.&amp;nbsp; I use the Thickness data set from the Sample Data Library.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open("$SAMPLE_DATA/Quality Control/Thickness.jmp");

stack_cols = {}; //list to hold the names of columns I want to stack
str_match = "Thickness"; //Substring in column name I want to find

names = dt &amp;lt;&amp;lt; Get Column Names;
for(i=1,i&amp;lt;=N Items(names),i++,
	If(Contains(char(names[i]),str_match) &amp;gt; 0,
		Insert Into(stack_cols, names[i])
	)
);

dt &amp;lt;&amp;lt; Stack(
	columns(stack_cols),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You would just need to replace the dt with your own table and str_match = "Vol Density"&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 17:00:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52818#M29914</guid>
      <dc:creator>cwillden</dc:creator>
      <dc:date>2018-03-08T17:00:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script for column stack by prefix for variable number of columns</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52925#M29953</link>
      <description>Thanks! If I wished to then recode the column (with a script) so that only the prefix remained i.e. so it read only S01, S02 etc., can this be done in a similar fashion to the stack?</description>
      <pubDate>Fri, 09 Mar 2018 16:27:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52925#M29953</guid>
      <dc:creator>nhun</dc:creator>
      <dc:date>2018-03-09T16:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Script for column stack by prefix for variable number of columns</title>
      <link>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52929#M29956</link>
      <description>&lt;P&gt;Yes, here's how you might do that:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For( i = 1, i &amp;lt;= N Col( dt ), i++,
	temp_name = Column( dt, i ) &amp;lt;&amp;lt; Get Name;
	If( Contains( temp_name, "Vol Density" ) &amp;gt; 0,
		Column( dt, i ) &amp;lt;&amp;lt; Set Name( Word( 1, temp_name ) )
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 16:41:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Script-for-column-stack-by-prefix-for-variable-number-of-columns/m-p/52929#M29956</guid>
      <dc:creator>cwillden</dc:creator>
      <dc:date>2018-03-09T16:41:52Z</dc:date>
    </item>
  </channel>
</rss>

