<?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 Putting a selected column name in a formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60408#M32914</link>
    <description />
    <pubDate>Fri, 15 Jun 2018 18:04:02 GMT</pubDate>
    <dc:creator>kevinatkodak</dc:creator>
    <dc:date>2018-06-15T18:04:02Z</dc:date>
    <item>
      <title>Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60408#M32914</link>
      <description />
      <pubDate>Fri, 15 Jun 2018 18:04:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60408#M32914</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-06-15T18:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60409#M32915</link>
      <description>&lt;P&gt;I'm trying to figure out how to get my column selection from a dialog box into a formula properly. I looked at lots of discussions and samples from the scripting book, tried a bunch of things. No dice yet. As you can see in the script, I want to select a column and make a new column based on the column moving average formula. I would appreciate help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my latest try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
colname = .;

New Window( "Select Column",
	x = Col List Box(
		Data Table( dt &amp;lt;&amp;lt; get name ),
		all,
		min col( 1 ),
		max col( 1 ),
		colname = Eval Expr (Expr(x &amp;lt;&amp;lt; get selected)[1]),
		dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", (x &amp;lt;&amp;lt; get selected)[1] )
	),
	
	
	Button Box( "Moving Average",
		dt &amp;lt;&amp;lt; New Column( Char( (x &amp;lt;&amp;lt; get selected)[1] ) || " Movin Average",
			Numeric,
			Formula( Col Moving Average( Name Expr(colname), 0, 4, 0 ) )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 18:08:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60409#M32915</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-06-15T18:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60410#M32916</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this. The last two lines of the col list box() part appeared to be a script, which means they should have been separated by the semicolon (or glue).&amp;nbsp; The rest of those lines are arguments of the col list box, separated by commas. The "colName = ... " part of the col list box is commented out here because I don't think it was doing much. Better to grab it during the button box part of the script. You can add back the table variable if you want it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be better to make the list box load numeric columns only. I couldn't remember how to do that correctly. Presently it loads all into the list box. I changed min / max col() to max selected. I.e. no more than 1 at a time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the formula part, it usually takes me a little trial and error to get strings where I want them. This seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
colname = .;

New Window( "Select Column",
	x = Col List Box(
		Data Table( dt &amp;lt;&amp;lt; get name ),
		all,//numeric,
		//min col( 1 ),
		max selected( 1 )//,
		//colname = Eval Expr (Expr(x &amp;lt;&amp;lt; get selected)[1])//,
		//dt &amp;lt;&amp;lt; New Table Variable( "Selected Column", (x &amp;lt;&amp;lt; get selected)[1] )
	),
	
	
	Button Box( "Moving Average",
		colName = Char( (x &amp;lt;&amp;lt; get selected)[1] );
		//myCol = column(colName);
		
		formulaString = "Col Moving Average( :"|| char(colName) ||", 0, 4, 0 )";
		
		dt &amp;lt;&amp;lt; New Column( colName  || " Movin Average",
			Numeric,
			//Formula( Col Moving Average( Name Expr(colname), 0, 4, 0 ) )
			Formula( eval(parse(formulaString)) )
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jun 2018 19:08:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60410#M32916</guid>
      <dc:creator>mikedriscoll</dc:creator>
      <dc:date>2018-06-15T19:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60422#M32926</link>
      <description>&lt;P&gt;Your script will work only if there are no special symbols in your column names. If there are then the named reference must be&amp;nbsp; :Name("string"). Also, a check that a column was selected was added to the script.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here(1);

dt = Current Data Table();
colname = .;

New Window( "Select Column",
	x = Col List Box(
		Data Table( dt &amp;lt;&amp;lt; get name ),
		all, &amp;lt;&amp;lt;Set Data Type("Numeric"),
		Max Selected(1)
	),
	
	
	Button Box( "Moving Average",
	  If(NItems(x &amp;lt;&amp;lt; get selected)==0, 
		   Caption("No columns are selected "); Wait(3); Caption(Remove)
		, //else
		colName = (x &amp;lt;&amp;lt; get selected)[1]; 
		formulaString = EvalInsert("\[Col Moving Average( :Name("^colName^"), 0, 4, 0 )]\");
		
		dt &amp;lt;&amp;lt; New Column( colName  || " Movin Average",
			Numeric,
			//Formula( Col Moving Average( Name Expr(colname), 0, 4, 0 ) )
			Formula( eval(parse(formulaString)) )
		); //end New Column
	  ) //end If
	) //end ButtonBox
); //New Window&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 21:40:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60422#M32926</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-06-15T21:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60496#M32958</link>
      <description>&lt;P&gt;Thank you, Mike,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yup, it did indeed work for me. And, I learned some more scripting technique.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 16:48:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60496#M32958</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-06-18T16:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60497#M32959</link>
      <description>&lt;P&gt;Thank you, GZ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, your solution worked for me too. Trapping if no column is selected is a good tip. I will use it going forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 16:50:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60497#M32959</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-06-18T16:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60513#M32962</link>
      <description>&lt;P&gt;No problem. But I would use gz's method. It is more robust in that it handles columns with special characters in the name.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:05:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60513#M32962</guid>
      <dc:creator>mikedriscoll</dc:creator>
      <dc:date>2018-06-18T18:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60516#M32965</link>
      <description>&lt;P&gt;OK. I will do so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a bunch,&lt;/P&gt;&lt;P&gt;Kevin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 18:12:16 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/60516#M32965</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-06-18T18:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83342#M37493</link>
      <description>&lt;P&gt;Continuing my effort. I've made a lot of progress.&amp;nbsp;I put a selected column name in my formula and can now make an overlay&amp;nbsp;graph of&amp;nbsp;the&amp;nbsp;selected column with its Moving Average using MA parameters from a dialog box. Nice. Very nice. I'm using the "Overlay Plot" function. I can modify all the points on both graphs, but cannot figure out how to modify just one of the plot's attributes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a code snippet to illustrate. This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;cn1 = colName || "";
cn2 = colName || " Moving Average";
dt &amp;lt;&amp;lt; New Column( colName || " Moving Average",
	Numeric,
	Formula( Eval( Parse( formulaString ) ) )
);
oc = Column( cn1 );
nc = Column( cn2 );
nw2 &amp;lt;&amp;lt; Close Window;
 
funny = Overlay Plot( Y( oc, nc ), );
funny &amp;lt;&amp;lt; (Connect Points( 1 ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="4"&gt;The resulting plot has both the MA and original&amp;nbsp;points connected.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="4"&gt;However, if I change the last line to modify just one of the plots, say, this, it doesn't work:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;funny &amp;lt;&amp;lt; oc( Connect Points( 1 ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="3"&gt;&lt;FONT face="Consolas"&gt;No points are connected.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="3"&gt;&lt;FONT face="Consolas"&gt;So, "oc" is recognized in the "Overlay Plot" function to be one of the Y columns, but not recognized in the above statement.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="3"&gt;&lt;FONT face="Consolas"&gt;Can someone help please? My mental health is at stake.:) I've attached a data table with my whole script embedded.&amp;nbsp;There is an additional small auto-generated script to make the plot the way I'd like the whole script to make it; I could only make this plot by manually changing the legend.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Consolas" size="3"&gt;&lt;FONT face="Consolas"&gt;Kevin&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Nov 2018 22:25:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83342#M37493</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-11-14T22:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83401#M37522</link>
      <description>&lt;P&gt;First a couple notes:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;oc is a column reference the syntax oc( Connect Points(1) ) could not be interpretted by JMP.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;It seems the syntax shown in the Scripting Index for the Overlay Plot requires the column name, see example below. It will also accept :Name("Volume")(Connect Color (0) );&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;obj = Overlay Plot(
	X( :Date ),
	Y( :High, :Low, :Close, :Volume ),
	Y Scale( Left, Left, Left, Right )
);
obj &amp;lt;&amp;lt; Connect Points( 1 );
obj &amp;lt;&amp;lt; :Volume( Connect Color( 0 ) );
obj &amp;lt;&amp;lt; :Low( Connect Color( "Red" ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;The overlay plot has some nice features, however, JMP developers would probably recommend using Graph Builder. For the structure of your data table, Overlay might be easier to use, so I will use Overlay.&lt;/LI&gt;&lt;LI&gt;The script below started with a subset of the Football data table, none of th ecolumns you added. Then computes teh Moving Average. The script creates an overlay plot and uses Eval(Parse(EvalInsert())) to construct the syntax shown in the Scripting Index with the quoted name and option to turn off points.&lt;/LI&gt;&lt;LI&gt;The second part of the script demonstartes an alternate method. Turn on lines and points for all overlay columns.&amp;nbsp; Then use Xpath() to create a list of references to the line segments and the marker segments.&amp;nbsp; To turn off a line, set the line width to 0. To turn off points, set the transparency to 0.&amp;nbsp; I find working with the segments uses simpler syntax.&amp;nbsp; However, Xpath() while extremely useful, is probably consisdered more advanced.&amp;nbsp; Hope that helps.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = current data table();

colnme = "Speed";

oc = Column(dt, colnme);
nc = dt &amp;lt;&amp;lt; New Column( colnme || " Moving Average",

     Numeric,
     Formula(Col Moving Average(oc[],1,4,16) )
     
 );
 
 ovp = Overlay Plot( Y(oc, nc));
 ovp &amp;lt;&amp;lt; Connect Thru Missing(1);
 ncnme = nc &amp;lt;&amp;lt; get name;
 
 //The syntax is ovp &amp;lt;&amp;lt; :col( opt1);
Eval( Parse(EvalInsert("ovp &amp;lt;&amp;lt;  :name(\!"^ncnme^\!")(Show Points(0))" ) ) ) ;

//alternate method 

 ovl = Overlay Plot( Y(oc, nc));
 ovl &amp;lt;&amp;lt; Connect Thru Missing(1);

lines  = ovl &amp;lt;&amp;lt; Xpath("//LineSeg");
points = ovl &amp;lt;&amp;lt; Xpath("//MarkerSeg");

wait(2); 
lines[1] &amp;lt;&amp;lt; Line width(0); //turn off line 1
wait(2);
lines[1] &amp;lt;&amp;lt; Line width(2); //turn on line 1
wait(2);
lines[1] &amp;lt;&amp;lt; Line width(0); //turn off line 1
wait(2);
points[2] &amp;lt;&amp;lt; Transparency(0); //turn off points 2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 02:16:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83401#M37522</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-11-15T02:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83485#M37565</link>
      <description>gzmorgan,&lt;BR /&gt;&lt;BR /&gt;You are a wizard. I tried both methods that you illustrated with success. More importantly, I learned more scripting technique. Many thanks.</description>
      <pubDate>Thu, 15 Nov 2018 13:51:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/83485#M37565</guid>
      <dc:creator>kevinatkodak</dc:creator>
      <dc:date>2018-11-15T13:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Putting a selected column name in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/105260#M38875</link>
      <description>&lt;P&gt;Hi &lt;A href="https://community.jmp.com/t5/user/viewprofilepage/user-id/70" target="_blank"&gt;gzmorgan0&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is a great script. How must the script chnaged in order to add other formula buttons, like Col Mean or Col Std Dev?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2019 19:45:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Putting-a-selected-column-name-in-a-formula/m-p/105260#M38875</guid>
      <dc:creator>Thomas1</dc:creator>
      <dc:date>2019-01-09T19:45:36Z</dc:date>
    </item>
  </channel>
</rss>

