<?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 account IDs with multiple account names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836733#M330827</link>
    <description>&lt;P&gt;I have the following sample data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input AcctID $4. ACCTNAME $12.;&lt;BR /&gt;cards;&lt;BR /&gt;1234 checking&lt;BR /&gt;1234 saving&lt;BR /&gt;1234 HSA-loan&lt;BR /&gt;5678 checking&lt;BR /&gt;8907 saving&lt;BR /&gt;7658 HSA-loan&lt;BR /&gt;4356 checking&lt;BR /&gt;4356 saving&lt;BR /&gt;9874 checking&lt;BR /&gt;9874 HSA-loan&lt;BR /&gt;5437 creditcard&lt;BR /&gt;5437 checking&lt;BR /&gt;5461 checking&lt;BR /&gt;5461 heloc-loan&lt;BR /&gt;2543 saving&lt;BR /&gt;2543 HSA-loan&lt;/P&gt;&lt;P&gt;7891 HSA-loan&lt;/P&gt;&lt;P&gt;7111 saving&amp;nbsp;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get the account IDs which has these conditions&lt;/P&gt;&lt;P&gt;1. Get all account IDs which has only 'checking' account name (no other account name is associated eg:&amp;nbsp;5678 checking)&lt;/P&gt;&lt;P&gt;2. If there is 'checking' account name along with 'saving' and 'HSA-loan' then I want to get those account IDs (eg: 1234 checking ,&amp;nbsp;1234 saving &amp;amp;&amp;nbsp;1234 HSA-loan).&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp;If there is 'checking' account name along with 'saving'&amp;nbsp; then get those account IDs (eg:&amp;nbsp;4356 checking &amp;amp;&amp;nbsp;4356 saving).&lt;/P&gt;&lt;P&gt;4.&amp;nbsp; If there is 'checking' account name along with&amp;nbsp;'HSA-loan' then I want to get those account IDs (eg:&amp;nbsp;9874 checking &amp;amp;&amp;nbsp;9874 HSA-loan)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to get any other account IDs especially if they are associated with account name of 'checking' and 'creditcard' etc or any Individual Account IDs which has account name as 'saving' or 'HSA-loan' individually or together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result should have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;AcctID ACCOUNT &lt;/U&gt;&lt;/P&gt;&lt;P&gt;1234 checking&lt;BR /&gt;1234 saving&lt;BR /&gt;1234 HSA-loan&lt;BR /&gt;5678 checking&lt;/P&gt;&lt;P&gt;4356 checking&lt;BR /&gt;4356 saving&lt;BR /&gt;9874 checking&lt;BR /&gt;9874 HSA-loan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select acctID,ACCTNAME&lt;BR /&gt;from HAVE&lt;BR /&gt;group by acctID,ACCTNAME&lt;BR /&gt;having (count(distinct ACCTNAME)=1 and UPCASE(ACCTNAME)='CHECKING')&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is yielding all the account IDs with checking and other account names are there. Could someone help me to get the result I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2022 14:55:11 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2022-10-04T14:55:11Z</dc:date>
    <item>
      <title>How to group account IDs with multiple account names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836733#M330827</link>
      <description>&lt;P&gt;I have the following sample data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input AcctID $4. ACCTNAME $12.;&lt;BR /&gt;cards;&lt;BR /&gt;1234 checking&lt;BR /&gt;1234 saving&lt;BR /&gt;1234 HSA-loan&lt;BR /&gt;5678 checking&lt;BR /&gt;8907 saving&lt;BR /&gt;7658 HSA-loan&lt;BR /&gt;4356 checking&lt;BR /&gt;4356 saving&lt;BR /&gt;9874 checking&lt;BR /&gt;9874 HSA-loan&lt;BR /&gt;5437 creditcard&lt;BR /&gt;5437 checking&lt;BR /&gt;5461 checking&lt;BR /&gt;5461 heloc-loan&lt;BR /&gt;2543 saving&lt;BR /&gt;2543 HSA-loan&lt;/P&gt;&lt;P&gt;7891 HSA-loan&lt;/P&gt;&lt;P&gt;7111 saving&amp;nbsp;&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get the account IDs which has these conditions&lt;/P&gt;&lt;P&gt;1. Get all account IDs which has only 'checking' account name (no other account name is associated eg:&amp;nbsp;5678 checking)&lt;/P&gt;&lt;P&gt;2. If there is 'checking' account name along with 'saving' and 'HSA-loan' then I want to get those account IDs (eg: 1234 checking ,&amp;nbsp;1234 saving &amp;amp;&amp;nbsp;1234 HSA-loan).&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp;If there is 'checking' account name along with 'saving'&amp;nbsp; then get those account IDs (eg:&amp;nbsp;4356 checking &amp;amp;&amp;nbsp;4356 saving).&lt;/P&gt;&lt;P&gt;4.&amp;nbsp; If there is 'checking' account name along with&amp;nbsp;'HSA-loan' then I want to get those account IDs (eg:&amp;nbsp;9874 checking &amp;amp;&amp;nbsp;9874 HSA-loan)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to get any other account IDs especially if they are associated with account name of 'checking' and 'creditcard' etc or any Individual Account IDs which has account name as 'saving' or 'HSA-loan' individually or together.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result should have&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;AcctID ACCOUNT &lt;/U&gt;&lt;/P&gt;&lt;P&gt;1234 checking&lt;BR /&gt;1234 saving&lt;BR /&gt;1234 HSA-loan&lt;BR /&gt;5678 checking&lt;/P&gt;&lt;P&gt;4356 checking&lt;BR /&gt;4356 saving&lt;BR /&gt;9874 checking&lt;BR /&gt;9874 HSA-loan&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select acctID,ACCTNAME&lt;BR /&gt;from HAVE&lt;BR /&gt;group by acctID,ACCTNAME&lt;BR /&gt;having (count(distinct ACCTNAME)=1 and UPCASE(ACCTNAME)='CHECKING')&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is yielding all the account IDs with checking and other account names are there. Could someone help me to get the result I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 14:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836733#M330827</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-10-04T14:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to group account IDs with multiple account names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836742#M330833</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/139130"&gt;@buddha_d&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the condition is: All values of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;upcase(acctname)&lt;/FONT&gt;&amp;nbsp;for an &lt;FONT face="courier new,courier"&gt;AcctId&lt;/FONT&gt; must be from the set {&lt;FONT face="courier new,courier"&gt;'CHECKING', 'SAVING', 'HSA-LOAN'&lt;/FONT&gt;} and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'CHECKING'&lt;/FONT&gt; must occur. Correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, this should select the observations in question:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select AcctID, acctname as ACCOUNT
from have
group by AcctID
having max(upcase(acctname)='CHECKING') &amp;amp; ~sum(upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN'))
order by AcctID, findc('csH',first(account),'i');
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Oct 2022 15:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836742#M330833</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-04T15:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to group account IDs with multiple account names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836772#M330847</link>
      <description>&lt;P&gt;I am running the query in DB. Once I pull the records, let me try this code. It works for me with the dummy data provided. Thank you so much, FreelanceReinhard.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 18:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836772#M330847</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-10-04T18:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to group account IDs with multiple account names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836793#M330854</link>
      <description>&lt;P&gt;Could you please explain me what this code doing here&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;PRE class=""&gt;&lt;CODE&gt; ~sum(upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN'))
order by AcctID, findc('csH',first(account),'i')&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 19:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836793#M330854</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2022-10-04T19:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to group account IDs with multiple account names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836803#M330857</link>
      <description>&lt;P&gt;As a Boolean expression,&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;is either 1 (TRUE) or 0 (FALSE) for an observation. Hence, the summary statistic&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;sum(&lt;/STRONG&gt;upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN')&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;is the number of observations in an AcctID "BY group" (note the GROUP BY clause) where that Boolean expression is TRUE. We are interested in the case that this number is zero because this means that no observation with an UPCASE(ACCTNAME) value other than 'CHECKING', 'SAVING' or 'HSA-LOAN' exists in the BY group. The possible values of that sum are 0, 1, 2, etc. Therefore, the condition&lt;/P&gt;
&lt;PRE&gt;sum(upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN'))&lt;STRONG&gt;=0&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;can also be written as&lt;/P&gt;
&lt;PRE&gt;~sum(upcase(acctname) ~in ('CHECKING', 'SAVING', 'HSA-LOAN'))&lt;/PRE&gt;
&lt;P&gt;because 0 -- interpreted as a Boolean value -- is FALSE, whereas all other non-missing numeric values are interpreted as TRUE. Feel free to replace &lt;FONT face="courier new,courier"&gt;~sum(...)&lt;/FONT&gt; with &lt;FONT face="courier new,courier"&gt;sum(...)=0&lt;/FONT&gt; if it's easier to understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ORDER BY clause is not necessary if the (virtually unpredictable) default order of observations produced by PROC SQL is good enough. My idea was to sort dataset WANT by AcctID and within an AcctID "BY group" by Account -- yet not alphabetically, but so that observations with UPCASE(Account)='CHECKING' come first, followed by&amp;nbsp;observations with UPCASE(Account)='SAVING', followed by&amp;nbsp;observations with UPCASE(Account)='HSA-LOAN'. The FINDC function searches the constant string "csH" and if it finds the first character of variable Account (i.e., the result of &lt;FONT face="courier new,courier"&gt;first(account)&lt;/FONT&gt;), irrespective of case (see modifier &lt;FONT face="courier new,courier"&gt;'i'&lt;/FONT&gt;), it returns the position of that character in the string: 1 for a "C", 2 for an "S" and 3 for an "H" -- so that sorting by this position number yields the intended order of the three possible values of&amp;nbsp; Account.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 20:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-account-IDs-with-multiple-account-names/m-p/836803#M330857</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-04T20:15:32Z</dc:date>
    </item>
  </channel>
</rss>

