<?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: How can I select a group of observations by facility for each ID? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596939#M171957</link>
    <description>&lt;P&gt;Good question&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp;, So it;s a business question as to how to deal with &lt;STRONG&gt;ties?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You got to tell us, which ones do you want to keep where there is a tie? How would you want to prioritize?&lt;/P&gt;</description>
    <pubDate>Wed, 16 Oct 2019 15:03:59 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-16T15:03:59Z</dc:date>
    <item>
      <title>How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596672#M171835</link>
      <description>&lt;P&gt;Hi, my dataset includes multiple diagnostic codes from multiple facilities for each patient. I want to only keep observations (ID)&amp;nbsp;for the FACILITY with the greatest number of diagnostic CODEs. Is there an easy way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, this:&lt;/P&gt;&lt;P&gt;ID FACILITY CODE&lt;/P&gt;&lt;P&gt;1 A 416000.1&lt;/P&gt;&lt;P&gt;1 A 751101.2&lt;/P&gt;&lt;P&gt;1 B 416000.1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;A 416000.1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;A 751101.2&lt;/P&gt;&lt;P&gt;2&amp;nbsp;B 416000.1&lt;/P&gt;&lt;P&gt;2 B 102000.1&lt;/P&gt;&lt;P&gt;2 B 102146.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;would become this:&lt;/P&gt;&lt;P&gt;ID FACILITY CODE&lt;/P&gt;&lt;P&gt;1 A 416000.1&lt;/P&gt;&lt;P&gt;1 A 751101.2&lt;/P&gt;&lt;P&gt;2&amp;nbsp;B 416000.1&lt;/P&gt;&lt;P&gt;2 B 102000.1&lt;/P&gt;&lt;P&gt;2 B 102146.2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amanda&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 22:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596672#M171835</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-15T22:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596673#M171836</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp; Assuming I understand your requirement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID FACILITY $ CODE;
cards;
1 A 416000.1
1 A 751101.2
1 B 416000.1
2 A 416000.1
2 A 751101.2
2 B 416000.1
2 B 102000.1
2 B 102146.2
;
 
proc sql;
create table want(drop=c) as
select *
from (select *,count(*) as c from have group id,facility)
group by id
having max(c)=c;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Oct 2019 22:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596673#M171836</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-15T22:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596674#M171837</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, my dataset includes multiple diagnostic codes from multiple facilities for each patient. I want to only keep observations (ID)&amp;nbsp;for the FACILITY with the greatest number of diagnostic CODEs. Is there an easy way to do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't understand the logic that gets your from input to output. Why isn't the third line of the input (1 B 416000.1) included in the output? Why aren't the rows that begin with 2 A in the output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2019 22:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596674#M171837</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-15T22:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596738#M171866</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;It can't get more concise than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s SQL where all procedural details are hidden behind the brain of the SQL optimizer. But the task offers a good proving ground for a nice exercise of making use of BY processing coupled with a hash table. Your sample data are sorted by ID FACILITY but not by CODE. Hence, we can take advantage of the sorted order and use a hash table to find the maximal number of distinct CODE values per FACILITY:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                
  input id facility $ code $ ;             
  cards ;                                  
1 A 416000.1                               
1 A 751101.2                               
1 B 416000.1                               
2 A 416000.1                               
2 A 751101.2                               
2 B 416000.1                               
2 B 102000.1                               
2 B 102146.2                               
;                                          
run ;                                      
                                           
data want (drop = _:) ;                    
  if _n_ = 1 then do ;                     
    dcl hash q () ;                        
    q.definekey ("code") ;                 
    q.definedone () ;                      
  end ;                                    
  do _n_ = q.clear() by 0 until (last.id) ;
    do until (last.facility) ;             
      set have ;                           
      by id facility ;                     
      q.ref() ;                            
    end ;                                  
    if q.num_items &amp;lt;= _qmax then continue ;
    _qmax = q.num_items ;                  
    _fmax = facility ;                     
  end ;                                    
  do until (last.id) ;                     
    set have ;                             
    by id ;                                
    if facility = _fmax then output ;      
  end ;                                    
run ;                                      
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if the input file were sorted by ID FACILITY CODE, BY processing alone would more than suffice:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = have out = shave ;                                                                                                     
  by id facility code ;                                                                                                                 
run ;                                                                                                                                   
                                                                                                                                        
data want (drop = _:) ;                                                                                                                 
  do until (last.id) ;                                                                                                                  
    do _q = 0 by 0 until (last.facility) ;                                                                                              
      set shave ;                                                                                                                       
      by id facility code ;                                                                                                             
      _q + first.code ;                                                                                                                 
    end ;                                                                                                                               
    if _q &amp;lt;= _qmax then continue ;                                                                                                      
    _qmax = _q ;                                                                                                                        
    _fmax = facility ;                                                                                                                  
  end ;                                                                                                                                 
  do until (last.id) ;                                                                                                                  
    set shave ;                                                                                                                         
    by id ;                                                                                                                             
    if facility = _fmax then output ;                                                                                                   
  end ;                                                                                                                                 
run ;                    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 04:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596738#M171866</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-16T04:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596847#M171909</link>
      <description>&lt;P&gt;Good morning Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; , Indeed classic and slick. However, it seems it's OP's very first post and tagged as &lt;EM&gt;"NewUser"&lt;/EM&gt;, so without taking away the potential of the prospect of great ability of new users, hmm nevertheless your level of Classics might be too overwhelming?&amp;nbsp; I recall reading your magnificent "DO" paper 3 years ago at a time when my experience was 2.5 years and that was mind boggling.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having said that, I know Paige miller and I are certainly benefited. So Thank you and Kudos &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 12:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596847#M171909</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-16T12:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596875#M171924</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; Sorry for the confusion. The logic that got me from the input to output was that ID#1 went to facility A (2 codes) and facility B (1 code), while ID#2 went to facility A (2 codes) and B (3 codes). I want to keep the facility with the most codes. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 13:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596875#M171924</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-16T13:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596877#M171926</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; Thanks for the response. I would have to agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; that you are at a level above. I will have to revisit your response when my skills improve.</description>
      <pubDate>Wed, 16 Oct 2019 13:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596877#M171926</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-16T13:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596878#M171927</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, Thank you! It worked. I should have asked sooner. I cannot believe how much time I wasted.</description>
      <pubDate>Wed, 16 Oct 2019 13:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596878#M171927</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-16T13:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596886#M171929</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp; &amp;nbsp;You are not alone. Join our club of learners. Btw, The purpose of this message is to let you know there is an amazing book by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp;&amp;nbsp;that covers all these topics. If and when you are interested, you may consider buying a copy from SAS Press or Amazon at some point. I have my university paid subscription to E-library safari-online.&amp;nbsp;&lt;/P&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;H3&gt;&lt;STRONG&gt;Data Management Solutions Using SAS&lt;SUP&gt;®&lt;/SUP&gt;&amp;nbsp;Hash Table Operations: A Business Intelligence Case Study&amp;nbsp;&lt;/STRONG&gt;&lt;/H3&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="text parbase section"&gt;
&lt;DIV class=""&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;SPAN class="xsmall-txt-light"&gt;By&amp;nbsp;&lt;A href="https://support.sas.com/en/books/authors/paul-dorfman.html" target="_blank" rel="noopener"&gt;Paul Dorfman&lt;/A&gt;(Hashman)&amp;nbsp;and&amp;nbsp;&lt;A href="https://support.sas.com/en/books/authors/don-henderson.html" target="_blank" rel="noopener"&gt;Don Henderson&lt;/A&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/14323"&gt;@ShelleySessoms&lt;/a&gt;&amp;nbsp; still is part of SAS press or can give you great leads regarding what's on offer, available discounts if any and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@Guru, do you wanna add a couple of points to get new OP's &lt;STRONG&gt;ease&lt;/STRONG&gt; into learning higher advance techniques in utilizing the book in the best way? You know what I mean &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; When i used your solutions at Citizens citing your reference, my team mates and fellow teams ran away hahahaa. So basically &lt;EM&gt;&lt;STRONG&gt;prerequisites&lt;/STRONG&gt; &lt;/EM&gt;needs before reading the book can help new folks not feel intimidated and enjoy reading and learning in their own pace.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 13:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596886#M171929</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-16T13:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596899#M171933</link>
      <description>&lt;P&gt;Thanks for the kinds words&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp;if you are not ready to buy a book, you might want to consider reviewing the articles that Paul and I (and others) have written related to the book. Just search the communities library using the tag &lt;A href="https://communities.sas.com/t5/forums/searchpage/tab/tkb?location=community%3Akntur85557&amp;amp;q=dmhashbook" target="_blank" rel="noopener"&gt;DMHashBook&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 13:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596899#M171933</guid>
      <dc:creator>DonH</dc:creator>
      <dc:date>2019-10-16T13:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596913#M171941</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. I used to be part of SAS Press, now strictly communities but still have great friends in SAS Press. Customers will find all the deals and discounts on books available at&amp;nbsp;&lt;A href="https://support.sas.com/en/books.html" target="_blank"&gt;https://support.sas.com/en/books.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596913#M171941</guid>
      <dc:creator>ShelleySessoms</dc:creator>
      <dc:date>2019-10-16T14:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596938#M171956</link>
      <description>&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="2"&gt;One&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; problem, how do I select only one facility for each ID when facilities have the same max?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;ID FACILITY CODE&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;416000.1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; A &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;751101.2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; B &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;416000.1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;&lt;STRONG&gt;3&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; B &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;416000.1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596938#M171956</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-16T14:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596939#M171957</link>
      <description>&lt;P&gt;Good question&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp;, So it;s a business question as to how to deal with &lt;STRONG&gt;ties?&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You got to tell us, which ones do you want to keep where there is a tie? How would you want to prioritize?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 15:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/596939#M171957</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-16T15:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597067#M172006</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: Thanks 1E6 for all the kind words.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To your "new user" point, methinks it merely indicates a new user of this discussion forum and not necessarily a new SAS user.&lt;/P&gt;
&lt;P&gt;Secondly, IMO, one can learn a lot from struggling to understand code (written by a solid programmer) that at first glance seems incomprehensible. Finally, what we post here is intended not solely for the OPs but for anyone who cares to read them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 19:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597067#M172006</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-16T19:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597076#M172007</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;I cannot thank you enough for the enthusiastic support of our opus since before it was even published, so let me add another thank you to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13569"&gt;@DonH&lt;/a&gt;&amp;nbsp;has already expressed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 19:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597076#M172007</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-16T19:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597125#M172018</link>
      <description>Thanks for being so nice. There is a fourth variable SEVERITY (ranging from 1-6, where 1 is least severe and 6 is most severe). I would want to keep patients with the most severe injuries, but I suspect there will be many ties (again). In the case of another tie, it wouldn't matter which facility was kept.</description>
      <pubDate>Wed, 16 Oct 2019 22:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597125#M172018</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-16T22:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597127#M172019</link>
      <description>&lt;P&gt;Okay&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp; &amp;nbsp;Take your time, examine the variables and your business requirement thoroughly and once you are clear, please post your&lt;EM&gt; modified input sample&lt;/EM&gt; and the &lt;EM&gt;expected output&lt;/EM&gt; for the new sample. Briefly add the logic notes why as in like your "Severity" variable.&amp;nbsp; Once we have this squeaky clean, coding is 5 mins work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 22:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597127#M172019</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-16T22:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597306#M172086</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, thank you and sorry for the confusion. My dataset includes multiple diagnostic codes from multiple facilities for each patient. I want to only keep observations (ID) for the FACILITY with the greatest number of diagnostic CODEs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID FACILITY $ CODE SEVERITY;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 A 416000.1 1&lt;/P&gt;&lt;P&gt;1 A 751101.2 2&lt;/P&gt;&lt;P&gt;1 B 416000.1 1&lt;/P&gt;&lt;P&gt;2 A 416000.1 1&lt;/P&gt;&lt;P&gt;2 A 751101.2 2&lt;/P&gt;&lt;P&gt;2 B 416000.1 1&lt;/P&gt;&lt;P&gt;2 B 102000.1 1&lt;/P&gt;&lt;P&gt;2 B 102146.2 2&lt;/P&gt;&lt;P&gt;3 A 416000.1 1&lt;/P&gt;&lt;P&gt;3 A 751101.2 2&lt;/P&gt;&lt;P&gt;3 B 416000.1 1&lt;/P&gt;&lt;P&gt;3 B 416000.1 1&lt;/P&gt;&lt;P&gt;4 A 416000.1 1&lt;/P&gt;&lt;P&gt;4 A 751101.2 1&lt;/P&gt;&lt;P&gt;4 B 416000.1 1&lt;/P&gt;&lt;P&gt;4 B 416000.1 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have already helped me determine how to use SAS to select FACILITY 1A and 2B (since they have the most CODEs), but FACILITY 3 A/B and 4 A/B both have two CODEs. I would like to select FACILITY 3A because it has a greater total SEVERITY (1+2). The SEVERITY scores for facility 4 A/B are tied, so it doesn’t matter which I include. In the WANT dataset I just included first FACILITY (4A).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WANT:&lt;/P&gt;&lt;P&gt;1 A 416000.1 1&lt;/P&gt;&lt;P&gt;1 A 751101.2 2&lt;/P&gt;&lt;P&gt;2 B 416000.1 1&lt;/P&gt;&lt;P&gt;2 B 102000.1 1&lt;/P&gt;&lt;P&gt;2 B 102146.2 2&lt;/P&gt;&lt;P&gt;3 A 416000.1 1&lt;/P&gt;&lt;P&gt;3 A 751101.2 2&lt;/P&gt;&lt;P&gt;4 A 416000.1 1&lt;/P&gt;&lt;P&gt;4 A 751101.1 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for sparing your valuable time to help!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597306#M172086</guid>
      <dc:creator>Amanda3</dc:creator>
      <dc:date>2019-10-17T12:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select a group of observations by facility for each ID?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597351#M172104</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295333"&gt;@Amanda3&lt;/a&gt;&amp;nbsp; Keeping it simple&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Modified the same SQL with a sum of severity and 
descending severity into a temp table for a rank order*/
proc sql;
create table temp(drop=c) as
select *
from (select *,count(*) as c,sum(severity) as s from have group id,facility)
group by id
having max(c)=c
order by id,facility,s desc; 
quit;
/*Using the rank order subsetting the ID facility that falls into the 
top order i.e n=1 and finally dropping all temp logic variables*/
data want;
set temp;
by id facility;
if first.id then n=1;
else if first.facility then  n+1;
if n=1;
drop n s ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:49:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-select-a-group-of-observations-by-facility-for-each-ID/m-p/597351#M172104</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-17T14:49:53Z</dc:date>
    </item>
  </channel>
</rss>

