<?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: get combination count in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763401#M241768</link>
    <description>&lt;P&gt;To make my question clear. Consider the following small size sample with 5 items and 10 customers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input c_id $ laptop TV cellphone monitor keyboard;
cards;
c1 1 0 0 0 1
c2 1 0 0 0 0
c3 1 0 0 0 0
c4 0 0 0 0 1
c5 1 0 0 0 1
c6 1 0 0 0 0
c7 0 0 0 0 1
c8 1 0 1 1 0
c9 1 0 1 1 0
c10 1 0 0 0 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So the result will be similar to the table below. It can be in other format as long as I can easily get the count of customer and items purchased begin identified.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;item_purchased&lt;/TD&gt;&lt;TD&gt;Customer_count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop; keyboard&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;keyboard&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop; cellphone; monitor&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 24 Aug 2021 01:59:07 GMT</pubDate>
    <dc:creator>sasecn</dc:creator>
    <dc:date>2021-08-24T01:59:07Z</dc:date>
    <item>
      <title>get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763398#M241765</link>
      <description>&lt;P&gt;I have a table of items that were purchased by customers listed by customer IDs. There are 300 items and 2000 customers. The table looks like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;c_id&lt;/TD&gt;&lt;TD&gt;Item1&lt;/TD&gt;&lt;TD&gt;Item2&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Item3&lt;/TD&gt;&lt;TD&gt;........&lt;/TD&gt;&lt;TD&gt;Item300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&amp;nbsp; &amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;......&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;.......&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;c2000&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The 0s and 1s indicate which items were purchased by certain customer. e.g. c1 purchased items 1, (may other items between 4 and 299), and 300. My goal is to get the counts of customers that have different item purchasing combinations. e.g. a result table like:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Item_purchased&lt;/TD&gt;&lt;TD&gt;Customer_count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Item1; Item5; Item6; Item300&lt;/TD&gt;&lt;TD&gt;45&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Item3; Item200&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Item4; Item100; Item299&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, the total of column Customer_count should be 2000. Since there are too many items, i cannot find a easy way to find those item combinations and put them in a table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure my question is clear or not. Can anyone help me with some ideas?&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 01:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763398#M241765</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2021-08-24T01:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763401#M241768</link>
      <description>&lt;P&gt;To make my question clear. Consider the following small size sample with 5 items and 10 customers:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input c_id $ laptop TV cellphone monitor keyboard;
cards;
c1 1 0 0 0 1
c2 1 0 0 0 0
c3 1 0 0 0 0
c4 0 0 0 0 1
c5 1 0 0 0 1
c6 1 0 0 0 0
c7 0 0 0 0 1
c8 1 0 1 1 0
c9 1 0 1 1 0
c10 1 0 0 0 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So the result will be similar to the table below. It can be in other format as long as I can easily get the count of customer and items purchased begin identified.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;item_purchased&lt;/TD&gt;&lt;TD&gt;Customer_count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop; keyboard&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;keyboard&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;laptop; cellphone; monitor&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 24 Aug 2021 01:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763401#M241768</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2021-08-24T01:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763413#M241776</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data KEY;
  length KEY $300;
  set HAVE;
  KEY=cats(of ITEM:);
run;
proc freq data=KEY;
  table KEY;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives you the count by unique combination.&lt;/P&gt;
&lt;P&gt;You can parse the KEY variable to replace the value by a list of item numbers if you want.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 04:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763413#M241776</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-24T04:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763419#M241778</link>
      <description>&lt;P&gt;Just for fun, what will you do if NONE of the combinations are duplicated? You have 2 to the 300th power possible combinations, that is roughly 2E90, or 2 followed by 90 zeroes, and only 2000 customers. That would make it not uncommon to have no duplicates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Slight modification of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; to get the variable names into the key.&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array v(*) laptop -- keyboard;
   length key $10000; /* for your full job*/
   do i=1 to dim(v);
      if v[i]=1 then key=catx(', ',key,vname(v[i]));
   end;
run;

proc freq data=want;
   tables key;
run;&lt;/PRE&gt;
&lt;P&gt;Vname is a function that will return the name of a variable (if used correctly).&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 05:58:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763419#M241778</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-24T05:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763420#M241779</link>
      <description>&lt;P&gt;This should get you close to the expected table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data combined;
   set have;
   
   length item_purchased $ 1000;
   array items laptop -- keyboard;
   
   do i = 1 to dim(items);
      if items[i] then do;
         item_purchased = catx(';', item_purchased, vname(items[i]));
      end;
   end;
   
   keep item_purchased;
run;


proc freq data=combined;
   table item_purchased / nocum nofreq nopercent;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: should have reloaded the topic before posting, to avoid cloning what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; already posted.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 06:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763420#M241779</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-24T06:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763503#M241819</link>
      <description>&lt;P&gt;Thank you! That works!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 13:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763503#M241819</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2021-08-24T13:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: get combination count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763504#M241820</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Aug 2021 13:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-combination-count/m-p/763504#M241820</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2021-08-24T13:26:25Z</dc:date>
    </item>
  </channel>
</rss>

