<?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 to count the number of each combination of two check-all-apply variables in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470731#M14747</link>
    <description>&lt;P&gt;This works perfectly! Much more efficient than PROC TRANSPOSE that I was using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate!&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jun 2018 22:40:15 GMT</pubDate>
    <dc:creator>zhouxysherry</dc:creator>
    <dc:date>2018-06-15T22:40:15Z</dc:date>
    <item>
      <title>How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470698#M14740</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset have:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="have.PNG" style="width: 528px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21224iF1C68B0AB25C9031/image-size/large?v=v2&amp;amp;px=999" role="button" title="have.PNG" alt="have.PNG" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dataset&amp;nbsp; want:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="want.PNG" style="width: 274px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21223iF6ED5D2B6DAA4539/image-size/medium?v=v2&amp;amp;px=400" role="button" title="want.PNG" alt="want.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable A and B are two check-all-apply variables in original dataset.&lt;/P&gt;&lt;P&gt;I want to get a frequency table which explicite all combinations of A,B, and C, and count the frequency of each combinations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 20:15:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470698#M14740</guid>
      <dc:creator>zhouxysherry</dc:creator>
      <dc:date>2018-06-15T20:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470710#M14743</link>
      <description>&lt;P&gt;Here is one way but may not be extensible easily if you are looking to do this with many more or groups of variables.&lt;/P&gt;
&lt;PRE&gt;data have;
   input A1-A3 B1-B4 C $;
datalines;
1 1 0 0 0 1 1 C1
0 1 1 0 0 1 0 C1
0 0 1 1 0 0 1 C3
;
run;

data trans;
   set have;
   array as a1-a3;
   array bs b1-b4;
   do i= 1 to dim(as);
      do j= 1 to dim(bs);
         if as[i]=1 and bs[j]=1 then do;
            A= vname(as[i]);
            B= vname(bs[j]);
            output;
         end;
      end;
   end;
   keep a b c;
run;

proc freq data=trans noprint;
  tables A*B*C/list out=want (drop=Percent);
run;&lt;/PRE&gt;
&lt;P&gt;Note that the data is in a data step to test code with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I believe your example output is incorrect as A2 = 1 on rows 1 and 2 and B3=1 on rows 1 and two. So the count for A2 B3 is 2 since the value of C is the same on both rows.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 21:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470710#M14743</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-15T21:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470718#M14745</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input A1-A3 B1-B4 C $;
datalines;
1 1 0 0 0 1 1 C1
0 1 1 0 0 1 0 C1
0 0 1 1 0 0 1 C3
;
run;

data want;
retain A B C;
set have;
array t(*) a1--b4;
do i=1 to dim(t)-1;
A=vname(t(i));
do j=i+1 to dim(t);
B=vname(t(j));
if first(vname(t(i))) ne first(vname(t(j))) then if t(i)+t(j)=2 then do;count=1;output;end;
end;
end;
keep A B C Count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jun 2018 21:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470718#M14745</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-15T21:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470731#M14747</link>
      <description>&lt;P&gt;This works perfectly! Much more efficient than PROC TRANSPOSE that I was using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really appreciate!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jun 2018 22:40:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470731#M14747</guid>
      <dc:creator>zhouxysherry</dc:creator>
      <dc:date>2018-06-15T22:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470733#M14748</link>
      <description>Thank you novinosrin! It's amazing that this could be finished in one step!&lt;BR /&gt;It works very well.</description>
      <pubDate>Fri, 15 Jun 2018 22:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470733#M14748</guid>
      <dc:creator>zhouxysherry</dc:creator>
      <dc:date>2018-06-15T22:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each combination of two check-all-apply variables</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470870#M14759</link>
      <description>&lt;P&gt;Just for fun, here's a little different version. It sets up a reference file of all of the possible responses, and then matches the input data against it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Set up a couple of formats */
proc format;
	value Af
		1 = "A1"
		2 = "A2"
		3 = "A3"
		. = "None"
	;
	value Bf
		1 = "B1"
		2 = "B2"
		3 = "B3"
		4 = "B4"
		. = "None"
	;
run;

/* Create a dataset that contains the desired results for different input patterns */
data Patterns;
	format A Af. B Bf.;
	keep Pattern A B;

	/* Get the A values with no B values */
	do APattern = 0 to 7;
		BPattern = 0;
		Pattern = APattern * 16 + BPattern;
		AChar = put(APattern, binary3.);

		do ACount = 1 to 3;
			call missing(A, B);

			if substr(AChar, ACount, 1) = "1" then
				A = ACount;

			if ^missing(A) then
				output;
		end;
	end;

	/* Get the B values with no A values */
	APattern = 0;

	do BPattern = 0 to 15;
		Pattern = APattern * 16 + BPattern;
		BChar = put(BPattern, binary4.);

		do BCount = 1 to 4;
			call missing(A, B);

			if substr(BChar, BCount, 1) = "1" then
				B = BCount;

			if ^missing(B) then
				output;
		end;
	end;

	/* Get the combinations of A values with B values */
	do APattern = 0 to 7;
		do BPattern = 0 to 15;
			Pattern = APattern * 16 + BPattern;
			AChar = put(APattern, binary3.);
			BChar = put(BPattern, binary4.);

			do ACount = 1 to 3;
				call missing(A);

				if substr(AChar, ACount, 1) = "1" then
					A = ACount;

				do BCount = 1 to 4;
					call missing(B);

					if substr(BChar, BCount, 1) = "1" then
						B = BCount;

					if ^missing(A) &amp;amp; ^missing(B) then
						output;
				end;
			end;
		end;
	end;
run;

/* Get the data */
data Have;
	length A1 A2 A3 B1 B2 B3 B4 8 C $2;
	input A1 A2 A3 B1 B2 B3 B4 C;
	SeqNo = _n_;
	cards;
1 1 0 0 0 1 1 C1
0 1 1 0 0 1 0 C1
0 0 1 1 0 0 1 C3
run;

/* Create the pattern to match with */
data Inter01;
	set Have;
	Pattern = B4*1 + B3*2 + B2*4 + B1*8 + A3*16 + A2*32 + A1*64;
run;

/* Match the input data to the patterns */
proc sql noprint;
	create table Want as
		select i.A1, i.A2, i.A3, i.B1, i.B2, i.B3, i.B4, p.A, p.B, i.C
			from Inter01 i inner join Patterns p on i.Pattern = p.Pattern
				order by SeqNo, A, B;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jun 2018 15:17:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-count-the-number-of-each-combination-of-two-check-all/m-p/470870#M14759</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-06-17T15:17:06Z</dc:date>
    </item>
  </channel>
</rss>

