<?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: Collapse observations by ID as well as some conditions in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391190#M11840</link>
    <description>Thank you! I like the codes.and get what i was looking for.&lt;BR /&gt;tot ID&lt;BR /&gt;38 1&lt;BR /&gt;0 2&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 28 Aug 2017 05:53:06 GMT</pubDate>
    <dc:creator>CSU_KL</dc:creator>
    <dc:date>2017-08-28T05:53:06Z</dc:date>
    <item>
      <title>Collapse observations by ID as well as some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391153#M11830</link>
      <description>&lt;P&gt;Hello all,&lt;BR /&gt;&lt;BR /&gt;In the attached example dataset, I want to get total min by ID. But the difficult points have two: first if the group = 0 (in white), the min will not count to the total. Second, if sub-total min of consecutive observations &amp;lt; 10 (in gray) where group = 1, then min will not count to the total either. So basically, I need to the total min in green by ID.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kaigang&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 21:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391153#M11830</guid>
      <dc:creator>CSU_KL</dc:creator>
      <dc:date>2017-08-27T21:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse observations by ID as well as some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391155#M11831</link>
      <description>&lt;P&gt;Not sure if I correctly understand what you want your output to look like. Sounds like the following might be what you're looking for:&lt;/P&gt;
&lt;PRE&gt;data want (drop=total);
  do until (last.group);
    set have;
    by id group notsorted;
    if group ne 0 then do;
      if first.group then total=min;
      else total+min;
    end;
    else total=0;
  end;
  do until (last.group);
    set have;
    by id group notsorted;
    if group ne 0 and total ge 10 then output;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 22:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391155#M11831</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-27T22:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse observations by ID as well as some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391179#M11838</link>
      <description>&lt;P&gt;To implement both conditions you need to calculate subtotals:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Min group @@; 
datalines;
1 2 1 1 3 1 1 4 1 1 5 0 1 2 0 1 3 0 1 4 1 
1 5 1 1 1 1 1 2 1 1 3 1 1 4 1 1 2 1 1 3 1 
1 1 0 1 1 0 1 1 0 1 2 1 1 3 1 1 4 1 1 2 1 
1 3 1 1 2 0 1 1 1 1 2 1 1 1 1 2 1 1 2 2 1 
2 1 1 2 2 0 2 2 0 2 10 0 2 1 0 2 1 1 2 1 1 
2 1 1 2 1 1 2 2 1 2 3 0 2 4 0 2 2 0 2 3 0 
2 3 0 2 1 1 2 3 1 2 1 1 2 1 1 
;

proc print data=have; by id group notsorted; id id group; run;

data want;
tot = 0;
do until (last.ID);
    stot = 0;
    do until (last.group);
        set have;
        by ID group notsorted;
        stot + min;
        end;
    if group ne 0 and not (group = 1 and stot &amp;lt; 10) then 
        tot + stot;
    end;
output;
keep ID tot;
run;

proc print noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Aug 2017 04:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391179#M11838</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-28T04:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse observations by ID as well as some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391189#M11839</link>
      <description>Your codes work. Thank you for your help!&lt;BR /&gt;&lt;BR /&gt;I would see the total so i removed the (drop=total) and get the output below.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;| Obs | ID | Min | group | total |&lt;BR /&gt;| 1 | 1 | 4 | 1 | 24 |&lt;BR /&gt;| 2 | 1 | 5 | 1 | 24 |&lt;BR /&gt;| 3 | 1 | 1 | 1 | 24 |&lt;BR /&gt;| 4 | 1 | 2 | 1 | 24 |&lt;BR /&gt;| 5 | 1 | 3 | 1 | 24 |&lt;BR /&gt;| 6 | 1 | 4 | 1 | 24 |&lt;BR /&gt;| 7 | 1 | 2 | 1 | 24 |&lt;BR /&gt;| 8 | 1 | 3 | 1 | 24 |&lt;BR /&gt;| 9 | 1 | 2 | 1 | 14 |&lt;BR /&gt;| 10 | 1 | 3 | 1 | 14 |&lt;BR /&gt;| 11 | 1 | 4 | 1 | 14 |&lt;BR /&gt;| 12 | 1 | 2 | 1 | 14 |&lt;BR /&gt;| 13 | 1 | 3 | 1 | 14 |&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Aug 2017 05:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391189#M11839</guid>
      <dc:creator>CSU_KL</dc:creator>
      <dc:date>2017-08-28T05:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse observations by ID as well as some conditions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391190#M11840</link>
      <description>Thank you! I like the codes.and get what i was looking for.&lt;BR /&gt;tot ID&lt;BR /&gt;38 1&lt;BR /&gt;0 2&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 28 Aug 2017 05:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Collapse-observations-by-ID-as-well-as-some-conditions/m-p/391190#M11840</guid>
      <dc:creator>CSU_KL</dc:creator>
      <dc:date>2017-08-28T05:53:06Z</dc:date>
    </item>
  </channel>
</rss>

