<?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 How to define a Count formula within a Subject in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29414#M19420</link>
    <description>&lt;P&gt;My data are organized such that an individual subject can have multiple lines of data, and each subject can have multiple dates/visits, and multiple lines of codes within each date/visit. However, the number of lines of data is different for each subject. I'm trying to count up the number of lines of data per subject, per date/visit, and lines of code within each date/visit. So, line 1=1, line 2=2, etc. All the formulas seem to require that I set a start and end number for a count, but that's not possible since the end varies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell me which formula I should be using and provide some advice on setting it up? Apparently I'm missing this in my interpretation.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 03 Oct 2017 14:55:07 GMT</pubDate>
    <dc:creator>jswislar</dc:creator>
    <dc:date>2017-10-03T14:55:07Z</dc:date>
    <item>
      <title>How to define a Count formula within a Subject</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29414#M19420</link>
      <description>&lt;P&gt;My data are organized such that an individual subject can have multiple lines of data, and each subject can have multiple dates/visits, and multiple lines of codes within each date/visit. However, the number of lines of data is different for each subject. I'm trying to count up the number of lines of data per subject, per date/visit, and lines of code within each date/visit. So, line 1=1, line 2=2, etc. All the formulas seem to require that I set a start and end number for a count, but that's not possible since the end varies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell me which formula I should be using and provide some advice on setting it up? Apparently I'm missing this in my interpretation.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2017 14:55:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29414#M19420</guid>
      <dc:creator>jswislar</dc:creator>
      <dc:date>2017-10-03T14:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29426#M19423</link>
      <description>&lt;P&gt;It sounds like you can get this through a table summary:&lt;/P&gt;&lt;P&gt;If you go to Tables--&amp;gt;Summary then select the columns you want to group by (e.g. subject, visit date). This will give you the number of rows that satisfy those conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below&amp;nbsp;gives number of students by age and gender:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dt = Open("$SAMPLE_DATA/Big Class.jmp")&amp;lt;&amp;lt; Summary(Group( :age, :sex ));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is that what you mean?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 16:48:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29426#M19423</guid>
      <dc:creator>mpl34</dc:creator>
      <dc:date>2016-11-21T16:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29428#M19425</link>
      <description>I don't need to the actual counts, but a new variable that I can use to sort and group by. For example, in another data set I was able to create a new variable that counted the number of rows and gave each row a number, per subject. That was possible sine every subject had 24 rows of data. In my current data set, some subjects have 1 row while other have 5 or 38 or 10, etc.&lt;BR /&gt;&lt;BR /&gt;so...&lt;BR /&gt;Subj visit code Counts_I_Want&lt;BR /&gt;001 1 7 1 1&lt;BR /&gt;001 1 5 2 2&lt;BR /&gt;001 2 3 3 1&lt;BR /&gt;001 3 7 4 1&lt;BR /&gt;001 3 6 5 2&lt;BR /&gt;002 1 4 1 1&lt;BR /&gt;003 1 7 1 1&lt;BR /&gt;003 2 5 2 1&lt;BR /&gt;003 2 0 3 2</description>
      <pubDate>Mon, 21 Nov 2016 16:59:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29428#M19425</guid>
      <dc:creator>jswislar</dc:creator>
      <dc:date>2016-11-21T16:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29429#M19426</link>
      <description>&lt;P&gt;You want something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;If&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;( &lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Row&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;() == &lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;, &lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;( :Subj[&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Row&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;()] == :Subj[&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Row&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;() - &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;], &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;:Count Formula[&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;&lt;FONT color="#0000dd" face="Consolas" size="2"&gt;Row&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;() - &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;] + &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;&lt;FONT face="Consolas" size="2"&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&lt;FONT color="#008080" face="Consolas" size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;)&lt;/P&gt;
&lt;P&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this assumes the data is sorted by the SUBJ column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 17:15:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29429#M19426</guid>
      <dc:creator>Dan_Obermiller</dc:creator>
      <dc:date>2016-11-21T17:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29431#M19428</link>
      <description>&lt;P&gt;try this one:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Syntax-How-do-I-create-an-index-column-by-ID/m-p/9755/highlight/true#M9541" target="_self"&gt;index&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 17:36:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29431#M19428</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2016-11-21T17:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29433#M19429</link>
      <description>&lt;P&gt;Col Number( :age, :age )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Col Number is a formula function in the Statistical group of function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It counts the number of things in a column&lt;/P&gt;&lt;P&gt;col number(:age) would ruturn the number of rows&lt;/P&gt;&lt;P&gt;col number(:age,:age) returns the number of times each Age occurs in the column for each row&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; if "14" shows up 10 times in the column, then for each row with a 14 in it, the formula returns "10."&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 17:49:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29433#M19429</guid>
      <dc:creator>Byron_JMP</dc:creator>
      <dc:date>2016-11-21T17:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29437#M19431</link>
      <description>&lt;P&gt;I see, then Dan's code should work. You can also use the lag function, so for you example data Subject Counts could be:&lt;/P&gt;&lt;P&gt;If(Lag(:Subj, 1) != :Subj | Is Missing(Lag(:Subj, 1)), 1, Lag(:Subj Counts, 1) + 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and visit counts could be:&lt;/P&gt;&lt;P&gt;If(Lag(:Subj, 1) != :Subj | Is Missing(Lag(:Subj, 1)) | Lag(:visit, 1) != :visit, 1, Lag(:Visit Counts, 1) + 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This still relies on sorting by subj and visit though.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 18:24:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29437#M19431</guid>
      <dc:creator>mpl34</dc:creator>
      <dc:date>2016-11-21T18:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count formula?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29439#M19432</link>
      <description>&lt;P&gt;The formula you want to use is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;col number(:Subj,:Visit)&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;col number(:Subj,:Subj,:Visit);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each row's value for Counts_I_Want will have the count of the number of rows for that subject for the visit&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2016 20:03:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-define-a-Count-formula-within-a-Subject/m-p/29439#M19432</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2016-11-21T20:03:27Z</dc:date>
    </item>
  </channel>
</rss>

