<?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 do nested counts in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962747#M83937</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My tendency would be to use PROC REPORT. I think report #3 in my example (using your test data) is closer to what you want. You can generate the PROC&amp;nbsp; REPORT output without any column headers at all; however, I rarely find a need to do that and using column headers keeps the report columns less confusing.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1743037408944.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105691iD3B3F72444B4AD16/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1743037408944.png" alt="Cynthia_sas_0-1743037408944.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Mar 2025 01:04:08 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2025-03-27T01:04:08Z</dc:date>
    <item>
      <title>How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962743#M83936</link>
      <description>&lt;P&gt;I'm a beginner to SAS. I'm trying to have nested counts presented cleanly as follows.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cluelesssas_0-1743033823619.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105690iB3E7A68886F04DF3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cluelesssas_0-1743033823619.png" alt="cluelesssas_0-1743033823619.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is code to generate toy data, as well as 3 attempts I tried (from hours of googling how to do this) that give the correct info, but none are as clean as the above. Imagine how awful they'd look when I need more than 2 layers of nesting. and multiplying together the total number of categories per variables is large, but the actual number of their combinations in the data is small.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data toy;
	input A $ B $;
	datalines;
A1 B1
A1 B2
A1 B2
A2 B1
A2 B1
A2 B1
A2 B2
A2 B2
A2 B2
A2 B2
;

proc tabulate data=toy;
	class A B;
	table A*(B all) all;
run;
proc summary data=toy print;
	class A B;
run;
proc freq data=toy;
	tables A*B / nopercent norow nocol;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Mar 2025 00:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962743#M83936</guid>
      <dc:creator>cluelesssas</dc:creator>
      <dc:date>2025-03-27T00:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962747#M83937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My tendency would be to use PROC REPORT. I think report #3 in my example (using your test data) is closer to what you want. You can generate the PROC&amp;nbsp; REPORT output without any column headers at all; however, I rarely find a need to do that and using column headers keeps the report columns less confusing.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1743037408944.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105691iD3B3F72444B4AD16/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1743037408944.png" alt="Cynthia_sas_0-1743037408944.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 01:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962747#M83937</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2025-03-27T01:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962752#M83938</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data toy;
	input A $ B $;
	datalines;
A1 B1
A1 B2
A1 B2
A2 B1
A2 B1
A2 B1
A2 B2
A2 B2
A2 B2
A2 B2
;

proc freq data=toy noprint;
	tables A*B /out=have list nopercent norow nocol;
run;
proc report data=have nowd ;
columns a b count;
define a/group noprint;
define b/group 'level';
define count/analysis 'count';
compute before a;
b=a;
endcomp;
compute b;
if missing(_BREAK_) then call define(_col_,'style','style={indent=0.25in}');
endcomp;
break before a/summarize;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_1-1743038560241.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105693i9544A5346FE03003/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_1-1743038560241.png" alt="Ksharp_1-1743038560241.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Mar 2025 01:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962752#M83938</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-27T01:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962861#M83940</link>
      <description>&lt;P&gt;thx Cynthia. What I ended up doing was based on your #2 proposal. I actually had 3 layers of nesting in my actual data (so imagine a variable C that we also want to nest under A and B in the toy data). This code seemed to do the job I hope it will generalize to future situations&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc report data=toy;
column A B C n;
define A / group;
define B / group;
define C / group;
define n / 'Count';
break before A / summarize;
break before B / summarize;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Mar 2025 17:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962861#M83940</guid>
      <dc:creator>cluelesssas</dc:creator>
      <dc:date>2025-03-28T17:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962938#M83941</link>
      <description>Hi:&lt;BR /&gt;  That is a simpler form of PROC REPORT since it doesn't have any compute blocks or style overrides. If that works for you, then that is going to be easier to code. I suggest you look on &lt;A href="http://www.lexjansen.com" target="_blank"&gt;www.lexjansen.com&lt;/A&gt; for PROC REPORT papers if you are new to using PROC REPORT.&lt;BR /&gt;Cynthia</description>
      <pubDate>Sat, 29 Mar 2025 16:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/962938#M83941</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2025-03-29T16:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/965077#M83963</link>
      <description>&lt;P&gt;I know this has been answered, but wouldn't a PROC MEANS (or SUMMARY) give all of the levels needed for this? It would then just be a sorting task to get something to print out. I have to admit the PROC REPORT approach more quickly yields a more esthetically pleasing output, but if the dataset is really large, with a lot of nesting, and you need to use the results for additional work, it might be worth taking a look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SteveDenham&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 18:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/965077#M83963</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2025-04-24T18:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to do nested counts</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/965093#M83964</link>
      <description>Yes.&lt;BR /&gt;But OP need pretty good layout like some margin before some levels.&lt;BR /&gt;That is unable to be done by PROC MEANS.&lt;BR /&gt;Since OP just only want a REPORT not a dataset, I think PROC REPORT is the only choice.</description>
      <pubDate>Fri, 25 Apr 2025 01:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-do-nested-counts/m-p/965093#M83964</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-04-25T01:24:26Z</dc:date>
    </item>
  </channel>
</rss>

