<?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: Transposing from WIDE to LONG and a formula question in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369666#M61935</link>
    <description>&lt;P&gt;I really appreciate your reply.&amp;nbsp; If memory serves you also helped me out with a question last year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I am not savvy with JMP script, only point and click.&amp;nbsp; And even if I could figure it out, since I have a lot of variables, I would have to run that code for each wouldn't I?&lt;/P&gt;</description>
    <pubDate>Fri, 19 Mar 2021 14:31:53 GMT</pubDate>
    <dc:creator>plfazeli</dc:creator>
    <dc:date>2021-03-19T14:31:53Z</dc:date>
    <item>
      <title>Transposing from WIDE to LONG and a formula question</title>
      <link>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369194#M61900</link>
      <description>&lt;P&gt;Hi--two somewhat related questions&lt;/P&gt;&lt;P&gt;I have used SPLIT to transform a long file to a wide file, but I have a slightly more complicated situation where I want to STACK/transpose a wide file to a long file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with a unique subject ID, and then several hundred columns/variables. The variable names are the exact same with the exception that Year 1 ends '2', Year 2 ends in '3', etc. Is there a relatively simple way to make this file long, such that there is a time variable (1,2,3,4) and the variable names are only in there once with no number at the end?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Related but approaching the above in a different way, in such a dataset, is there a way to create a formula in JMP to tell it for all XXX hundred columns, to remove the # (e.g., 1, 2) from the end of the column/variable name? Obviously I could do that manually but it would take forever.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:27:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369194#M61900</guid>
      <dc:creator>plfazeli</dc:creator>
      <dc:date>2023-06-10T23:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing from WIDE to LONG and a formula question</title>
      <link>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369254#M61902</link>
      <description>&lt;P&gt;Here is a script that will generate a stacked data table with 3 columns&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="x1.PNG" style="width: 428px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31358i9A9FA4F7F514562B/image-dimensions/428x502?v=v2" width="428" height="502" role="button" title="x1.PNG" alt="x1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is a script that will strip off the numerical number from the end of columns in a data table.&amp;nbsp; Remember, when renaming columns, if the end result is a column name that is the same as a previous column's name, JMP will add a numeric value to make the new column name a unique name&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();
For( i = 1, i &amp;lt;= N Cols( dt ), i++,
	if(
		is missing(
			Num(
				word(
					-1,
					Lowercase( Column( dt, i ) &amp;lt;&amp;lt; get name )
				,
				"abcdefghijklmnopqrstuvwxyz;:, -_)(")
			)
		) == 0,
		Column( dt, i ) &amp;lt;&amp;lt;
		set name(
			substr(
				Column(dt,i)&amp;lt;&amp;lt;get name,
				1,
				Length( Column(dt,i)&amp;lt;&amp;lt;get name )
				-Length(
					Word(
						-1,
						Lowercase( Column(dt,i)&amp;lt;&amp;lt;get name ),
						"abcdefghijklmnopqrstuvwxyz;:, -_)("
					)
				)
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = new table( "Example",
	add rows( 10 ),
	New Column( "Year2", formula( Random Integer( 1, 100 ) ) ),
	New Column( "Year3", formula( Random Integer( 1, 100 ) ) ),
	New Column( "Year4", formula( Random Integer( 1, 100 ) ) )
);

dtStack = Data Table( "Example" ) &amp;lt;&amp;lt; Stack(
	columns( :Year2, :Year3, :Year4 ),
	Source Label Column( Column ),
	Stacked Data Column( "Data" )
);

dtStack &amp;lt;&amp;lt; New Column( "Year",
	formula(
		Num(
			Word(
				-1,
				Lowercase( :Column ),
				"abcdefghijklmnopqrstuvwxyz;:, -_)("
			)
		)
	)
);
dtStack:Year &amp;lt;&amp;lt; delete formula;
for each row(
	:Column = substr(
		:Column,
		1,
		Length( :Column ) - Length(
			Word(
				-1,
				Lowercase( :Column ),
				"abcdefghijklmnopqrstuvwxyz;:, -_)("
			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Mar 2021 14:38:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369254#M61902</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-19T14:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing from WIDE to LONG and a formula question</title>
      <link>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369666#M61935</link>
      <description>&lt;P&gt;I really appreciate your reply.&amp;nbsp; If memory serves you also helped me out with a question last year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I am not savvy with JMP script, only point and click.&amp;nbsp; And even if I could figure it out, since I have a lot of variables, I would have to run that code for each wouldn't I?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 14:31:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369666#M61935</guid>
      <dc:creator>plfazeli</dc:creator>
      <dc:date>2021-03-19T14:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing from WIDE to LONG and a formula question</title>
      <link>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369709#M61940</link>
      <description>&lt;P&gt;I will guide you through generating the stacked data table, using the below data table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="e1.PNG" style="width: 359px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31391i2FC14FFC0B086172/image-size/large?v=v2&amp;amp;px=999" role="button" title="e1.PNG" alt="e1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Go to&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Tables=&amp;gt;Stack&lt;/P&gt;
&lt;P&gt;Fill out the dialog window by placing all of the columns you want to stack into the Stack Columns selection box.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s2.PNG" style="width: 554px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31392i9ED95AC314026DCF/image-size/large?v=v2&amp;amp;px=999" role="button" title="s2.PNG" alt="s2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It will create a table that looks like this&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s3.PNG" style="width: 311px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31393iD35E1294754C15AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="s3.PNG" alt="s3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Create a new column in the data table called "Column Name"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s4.PNG" style="width: 423px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31394iAB1EA11875FD9B73/image-size/large?v=v2&amp;amp;px=999" role="button" title="s4.PNG" alt="s4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Right click on the column header for the Column Name column, and select Formula&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s5.PNG" style="width: 602px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31395i06F2BC6E2DCA348D/image-size/large?v=v2&amp;amp;px=999" role="button" title="s5.PNG" alt="s5.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;A formula needs to be specified that takes everything before the numbers at the end of the values in the column Label and keeps that as the Column Name value.&amp;nbsp; So this can be done several ways, depending upon the actual data.&amp;nbsp; In our example, the formula will find everything before any numbers are seen and take that as the Column Name value.&lt;/P&gt;
&lt;P&gt;The formula finds the 1st word in the :Label column, stopping whenever it finds any numeric value "0123456789"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s6.PNG" style="width: 868px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31396i341608AF58401242/image-size/large?v=v2&amp;amp;px=999" role="button" title="s6.PNG" alt="s6.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The result is&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s7.PNG" style="width: 401px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31397iFD3105F561BD19DE/image-size/large?v=v2&amp;amp;px=999" role="button" title="s7.PNG" alt="s7.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now create another new column and call it "Year".&amp;nbsp; In this case, we want to take the last character in the column as the value of year formula is&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s8.PNG" style="width: 919px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31399iB40E8FC74CEFF4CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="s8.PNG" alt="s8.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Which gives you your final data table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="s9.PNG" style="width: 429px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/31400i1AAAEC4F193600B0/image-size/large?v=v2&amp;amp;px=999" role="button" title="s9.PNG" alt="s9.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Concerning the renaming of the columns, I do not know an interactive way of doing that interactively.&amp;nbsp; So I think you will have to run the script that I provided earlier&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 15:16:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Transposing-from-WIDE-to-LONG-and-a-formula-question/m-p/369709#M61940</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-03-19T15:16:20Z</dc:date>
    </item>
  </channel>
</rss>

