<?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 counts by groups across columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748560#M235086</link>
    <description>&lt;P&gt;Okay, I think I got something that will work for you but I had to add a variable called ID and it has values 1-4 for each of the 4 rows. Basically, you make 3 datasets and transpose them by pos, neg, and age and then merge all the datasets together. From there, you can sum down the columns grouping by age. Take a look. I tried to attach an image but it's not working. Just print out the dataset test3 and see if it meets your needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id pos1-pos5 neg1-neg5 age1 $ age2 $ age3 $ age4 $ age5 $;
cards;
1 1 0 0 0 0 0 0 0 0 0 10-14 15-19 20-24 25-29 30+
2 0 1 0 0 0 1 0 0 0 0 10-14 15-19 10-14 30+ 20-24
3 1 1 0 0 0 0 0 1 0 0 30+ 20-24 25-29 15-19 20-24
4 0 0 1 1 0 1 1 0 0 1 20-24 25-29 10-14 15-19 20-24
;
run;

*output 3 datasets from proc transpose, one for age, one for pos, one for neg;
proc transpose data=test out=longp prefix=pos;
	by ID;
	var pos1-pos5;
run;

proc transpose data=test out=longn prefix=neg;
	by ID;
	var neg1-neg5;
run;

proc transpose data=test out=longa prefix=age;
	by ID;
	var age1-age5;
run;

*create test2 ds by merging the 3 transposed datasets together;
data test2;
	merge longp(rename=(pos1=pos) drop=_name_) longn(rename=(neg1=neg) drop=_name_) longa
	(rename=(age1=age));
	by ID;
	drop _name_;
run;

proc print data=test2;run;

proc sql;
	create table test3 as select age, sum(pos) as pos, sum(neg) as neg
		from test2
		group by age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Jun 2021 20:50:04 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2021-06-16T20:50:04Z</dc:date>
    <item>
      <title>Get counts by groups across columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748548#M235084</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;
&lt;P&gt;(Sorry for duplicating questions, lost my previous post).&lt;/P&gt;
&lt;P&gt;I have data on 5 partners for each client, partner1-5. I have their test results, POS or NEG for each partner POS1-5 and NEG1-5 (coded 1 if yes, 0 if no). I also have age of the partners, Age1-5. Data snapshot below&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 1056pt;" border="0" width="1408" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.4pt; width: 48pt;"&gt;Partner1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Partner2&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Partner3&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Partner4&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Partner5&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS2&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS3&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS4&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS5&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG2&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG3&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG4&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG5&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Age1&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Age2&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Age3&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Age4&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Age5&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NPOS&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NNEG&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;10-14&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;15-19&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;25-29&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;30+&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;10-14&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;15-19&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;10-14&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;30+&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;30+&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;25-29&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;15-19&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" align="right" class="xl65" style="height: 14.4pt; border-top: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;0&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;25-29&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;10-14&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;15-19&lt;/TD&gt;
&lt;TD class="xl66" style="border-top: none; border-left: none;"&gt;20-24&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I created the counts for nPOS and nNEG by Sum(of Pos1-Pos5) and Sum(of Neg1-Neg5). I am trying to get count of POS ans NEGs by age group. Meaning the distribution of age group among POS and among NEG. Output below :&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.4pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;POS&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;NEG&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl66" style="height: 14.4pt; border-top: none;"&gt;10-14&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl66" style="height: 14.4pt; border-top: none;"&gt;15-19&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl66" style="height: 14.4pt; border-top: none;"&gt;20-24&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl66" style="height: 14.4pt; border-top: none;"&gt;25-29&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" class="xl66" style="height: 14.4pt; border-top: none;"&gt;30+&lt;/TD&gt;
&lt;TD align="right" class="xl65" style="border-top: none; border-left: none;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions on how to get the counts would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;THanks in advance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 19:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748548#M235084</guid>
      <dc:creator>rsva</dc:creator>
      <dc:date>2021-06-16T19:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get counts by groups across columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748560#M235086</link>
      <description>&lt;P&gt;Okay, I think I got something that will work for you but I had to add a variable called ID and it has values 1-4 for each of the 4 rows. Basically, you make 3 datasets and transpose them by pos, neg, and age and then merge all the datasets together. From there, you can sum down the columns grouping by age. Take a look. I tried to attach an image but it's not working. Just print out the dataset test3 and see if it meets your needs.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input id pos1-pos5 neg1-neg5 age1 $ age2 $ age3 $ age4 $ age5 $;
cards;
1 1 0 0 0 0 0 0 0 0 0 10-14 15-19 20-24 25-29 30+
2 0 1 0 0 0 1 0 0 0 0 10-14 15-19 10-14 30+ 20-24
3 1 1 0 0 0 0 0 1 0 0 30+ 20-24 25-29 15-19 20-24
4 0 0 1 1 0 1 1 0 0 1 20-24 25-29 10-14 15-19 20-24
;
run;

*output 3 datasets from proc transpose, one for age, one for pos, one for neg;
proc transpose data=test out=longp prefix=pos;
	by ID;
	var pos1-pos5;
run;

proc transpose data=test out=longn prefix=neg;
	by ID;
	var neg1-neg5;
run;

proc transpose data=test out=longa prefix=age;
	by ID;
	var age1-age5;
run;

*create test2 ds by merging the 3 transposed datasets together;
data test2;
	merge longp(rename=(pos1=pos) drop=_name_) longn(rename=(neg1=neg) drop=_name_) longa
	(rename=(age1=age));
	by ID;
	drop _name_;
run;

proc print data=test2;run;

proc sql;
	create table test3 as select age, sum(pos) as pos, sum(neg) as neg
		from test2
		group by age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jun 2021 20:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748560#M235086</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-06-16T20:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get counts by groups across columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748563#M235088</link>
      <description>&lt;P&gt;Is it every possible for a partner to have both a positive and negative result? If not you only need one variable with the information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a different approach to reshaping data with arrays and explicit output statement.&lt;/P&gt;
&lt;PRE&gt;data test;
input id partner1-partner5 pos1-pos5 neg1-neg5 age1 $ age2 $ age3 $ age4 $ age5 $;
cards;
1 1 . . . . 1 0 0 0 0 0 0 0 0 0 10-14 15-19 20-24 25-29 30+
2 1 1 . . . 0 1 0 0 0 1 0 0 0 0 10-14 15-19 10-14 30+ 20-24
3 1 1 1 . . 1 1 0 0 0 0 0 1 0 0 30+ 20-24 25-29 15-19 20-24
4 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 20-24 25-29 10-14 15-19 20-24
;
run;

data want;
   set test;
   array pa(*) partner1-partner5;
   array p (*) pos1-pos5;
   array n (*) neg1-neg5;
   array a (*) age1-age5;
   do partner=1 to dim(pa);
      if pa[partner]=1 then do; 
         pos=p[partner];
         neg=n[partner];
         age=a[partner];
         output;
      end;
   end; 
   keep id partner pos neg age;
run;

proc tabulate data=want;
  class age;
  var pos neg;
  table age=' ',
        (pos neg) * sum=' '*f=best5.
        /misstext=' '
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;You will find that for most cases that a long data set with one observation per set of measurements will work better.&lt;/P&gt;
&lt;P&gt;And here is what I meant by using just one variable :&lt;/P&gt;
&lt;PRE&gt;proc format;
value pn 
1=' Pos'
0='Neg'
;
proc tabulate data=want;
  class age;
  class pos/order=formatted;
  format pos pn.;
  table age=' ',
        pos=' ' * n=' '
        /misstext=' '
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;Playing some minor games to duplicate the order you showed.&lt;/P&gt;
&lt;P&gt;In Proc Tabulate you can use variable= to override default variable labels and if you use age=' ' the space supresses the label entirely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jun 2021 21:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748563#M235088</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-16T21:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Get counts by groups across columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748714#M235163</link>
      <description>&lt;P&gt;THanks for the solution.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 15:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748714#M235163</guid>
      <dc:creator>rsva</dc:creator>
      <dc:date>2021-06-17T15:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Get counts by groups across columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748715#M235164</link>
      <description>&lt;P&gt;Thanks for the solution. Both solutions worked perfectly.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jun 2021 15:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Get-counts-by-groups-across-columns/m-p/748715#M235164</guid>
      <dc:creator>rsva</dc:creator>
      <dc:date>2021-06-17T15:17:58Z</dc:date>
    </item>
  </channel>
</rss>

