<?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 group using last 2 characters and subset the latest data? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748501#M92906</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to make a column for groupings using the last two characters from another column? For example, I have this table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FYW&lt;/TD&gt;&lt;TD&gt;Groupings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W38&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W38&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W40&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W41&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W41&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it also possible to subset the first 2 latest date according to the grouping? In this example,&amp;nbsp;FY24W40 and&amp;nbsp;FY24W41 will be selected then subset since they are the "latest" data. TIA&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Apr 2024 23:39:39 GMT</pubDate>
    <dc:creator>UserID16644</dc:creator>
    <dc:date>2024-04-22T23:39:39Z</dc:date>
    <item>
      <title>How to group using last 2 characters and subset the latest data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748501#M92906</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to make a column for groupings using the last two characters from another column? For example, I have this table:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;FYW&lt;/TD&gt;&lt;TD&gt;Groupings&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W38&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W38&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W39&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W40&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W41&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;FY24W41&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it also possible to subset the first 2 latest date according to the grouping? In this example,&amp;nbsp;FY24W40 and&amp;nbsp;FY24W41 will be selected then subset since they are the "latest" data. TIA&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2024 23:39:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748501#M92906</guid>
      <dc:creator>UserID16644</dc:creator>
      <dc:date>2024-04-22T23:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to group using last 2 characters and subset the latest data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748509#M92910</link>
      <description>&lt;P&gt;Here is the formula to use to create the groupings&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Col Cumulative Sum( Right( :FYW, 2 ) != Lag( Right( :FYW, 2 ) ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a simple script to find the 2 highest values of FYW and to create a subset with only those rows that match the highest 2 values&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

dt=current data table();

array=associative array(:fyw&amp;lt;&amp;lt;get values)&amp;lt;&amp;lt;get keys;

dt &amp;lt;&amp;lt; select where(:FYW == array[length(array)-1] | :FYW == array[length(array)] );

dtSubset = dt &amp;lt;&amp;lt; subset( selected rows( 1 ), selected columns( 0 ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 01:56:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748509#M92910</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2024-04-23T01:56:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to group using last 2 characters and subset the latest data?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748520#M92917</link>
      <description>&lt;P&gt;It can also be a good idea to consider creating new column for your weeks (might make it simpler for you to solve) and then use that and you can easily create this column using Recode&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1713845764025.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/63549i12C8E65E493BC9AB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1713845764025.png" alt="jthi_0-1713845764025.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then create your grouping column with a formula (using same formula as Jim but "newly" created column W)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	Col Cumulative Sum(:W != Lag(:W))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then you can create summary (this can be built in many different ways depending on how you want to select your values), change Group order, select first two rows from summary and create your subset from your original table&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1713846284298.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/63551i45785D26DAD40CFB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1713846284298.png" alt="jthi_2-1713846284298.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt_summary &amp;lt;&amp;lt; Select Rows([1, 2]);
dt_subset = dt &amp;lt;&amp;lt; Subset(Selected Rows(1), columns(:FYW));
Close(dt_summary, no save);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2024 04:26:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-group-using-last-2-characters-and-subset-the-latest-data/m-p/748520#M92917</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-04-23T04:26:50Z</dc:date>
    </item>
  </channel>
</rss>

