<?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: Dynamic Column Reference in Function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/187181#M40578</link>
    <description>This is great now I got it.&lt;BR /&gt;Thanks very much! Really appreciate it.</description>
    <pubDate>Fri, 15 Mar 2019 07:04:38 GMT</pubDate>
    <dc:creator>safwan</dc:creator>
    <dc:date>2019-03-15T07:04:38Z</dc:date>
    <item>
      <title>Dynamic Column Reference in Function</title>
      <link>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/186875#M40539</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to write a function that&amp;nbsp;refers to a&amp;nbsp;certain row of a column and trying to make it dynamic where I can run it on any column name. Using the Big Class table as sample, I'm trying to run the calculation on the height&amp;nbsp;column but I couldn't get it working&amp;nbsp;unless&amp;nbsp;its hardcoded&amp;nbsp;in the function. Also the lag function doesn't seem to work within a function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the script that I have.&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;dt = &lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Open&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;( &lt;/FONT&gt;&lt;FONT color="#800080" face="Consolas" size="2"&gt;"$SAMPLE_DATA/Big Class.jmp"&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt; );&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Row() = 4;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;ii = &lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;4&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Test = &lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Function&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;({tag},&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Y = tag[ii] - tag[ii-&lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;]; // this doesn't work&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//Y = height[ii] - height[ii-1]; this works&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;X = &lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;lag&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(tag,&lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;); // this doesn't work&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Consolas" size="2"&gt;//X = lag(height,1); this works&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;Test(height)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 07:23:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/186875#M40539</guid>
      <dc:creator>safwan</dc:creator>
      <dc:date>2019-03-14T07:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Column Reference in Function</title>
      <link>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/186922#M40543</link>
      <description>&lt;P&gt;See the annotated script below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;t = Open( "$SAMPLE_DATA/Big Class.jmp" );
Row() = 4;
ii = 4;
Test = Function({tag},
Y = column(t,tag)[ii] - column(t,tag)[ii-1]; // this doesn't work
//Y = height[ii] - height[ii-1]; this works
X = lag(column(t,tag)[ii],1); // this doesn't work
//X = lag(height,1); this works
// If you want the calculated values to be returned to a value such as calling the function
//  rr = Test("Height")
// uncomment the code below
//YXList = {};
//insert into(YXList,Y);
//insert into(YXList,X);
//return(YXList);
);

// If you specify 
// Test(height);
// JMP will look for the value of a variable called height
// You need to pass the column name as a string and have the
// function process it
Test("height")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Mar 2019 09:26:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/186922#M40543</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2019-03-14T09:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Column Reference in Function</title>
      <link>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/187181#M40578</link>
      <description>This is great now I got it.&lt;BR /&gt;Thanks very much! Really appreciate it.</description>
      <pubDate>Fri, 15 Mar 2019 07:04:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Dynamic-Column-Reference-in-Function/m-p/187181#M40578</guid>
      <dc:creator>safwan</dc:creator>
      <dc:date>2019-03-15T07:04:38Z</dc:date>
    </item>
  </channel>
</rss>

