<?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: Proc tabulate: show subtotals by variable and suppress missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949003#M371273</link>
    <description>&lt;P&gt;OK. If I understand what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.heart(obs=200);
run;

proc sql;
create table report as
select 'DeathCause' as a,' '||DeathCause as b,sex as c,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where DeathCause is not missing
   group by DeathCause,Sex
union all
select 'DeathCause' ,'SubTotal',sex,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where sex is not missing 
   group by sex

union all

select 'bp_status' as a,' '||bp_status as b,sex as c,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where bp_status is not missing
   group by bp_status,Sex
union all
select 'bp_status' ,'SubTotal',sex,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where sex is not missing
   group by sex
;
quit;



proc report data=report nowd;
columns a b c,(_n p);
define a/group noprint;
define b/group '';
define c/across '';
compute before a/style={just=l};
line a $40.;
endcomp;
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_0-1729828063250.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101803i3A882398B4129528/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1729828063250.png" alt="Ksharp_0-1729828063250.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2024 03:47:56 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-10-25T03:47:56Z</dc:date>
    <item>
      <title>Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948802#M371190</link>
      <description>&lt;P&gt;I am using proc tabulate to show demographic characteristics of a client population over several years. There are some missing values, and my understanding is that proc tabulate excludes the entire observation if a value for any variable in the class statement is missing. I want to keep all observations and show subtotals by demographic characteristic, without having a "Missing" or "Unknown" category for each group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lml819_1-1729708853531.png" style="width: 430px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101744iB53E6CFE4B8529D4/image-dimensions/430x345?v=v2" width="430" height="345" role="button" title="lml819_1-1729708853531.png" alt="lml819_1-1729708853531.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I want:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lml819_0-1729708829914.png" style="width: 432px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101743i2F9FA2137C6261CB/image-dimensions/432x301?v=v2" width="432" height="301" role="button" title="lml819_0-1729708829914.png" alt="lml819_0-1729708829914.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Simplified version of code (I have several more class variables in the actual dataset):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc tabulate data=all;
class raceeth gender year/missing;
table (raceeth all='Subtotal')(gender all='Subtotal'), year*(N='No.' colpctn='%'*f=5.1);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is this possible in proc tabulate, or do I need to use a different method?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 18:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948802#M371190</guid>
      <dc:creator>lml819</dc:creator>
      <dc:date>2024-10-23T18:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948811#M371196</link>
      <description>&lt;P&gt;Instead of printing the table, put the output into a data set.&amp;nbsp; Do not bother with subsets or percentages, just keep the original counts.&amp;nbsp; If it's easier for you, just use PROC SUMMARY to get the counts into an output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use a DATA step to remove the missing categories from that output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then feed the remaining subset with no missing values back into a new PROC TABULATE to print your table.&amp;nbsp; Since you already have totals, you may need to switch to the SUM statistic (and pctSUM) instead of N (and pctN).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are 100% correct about PROC TABULATE removing observations where even one class variable has a missing value.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 20:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948811#M371196</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-10-23T20:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948847#M371212</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;&amp;nbsp;I want to keep all observations and show subtotals"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I don't understand. If you want to count all the obs (include missing value) and don't want display mssing value in report ,then you need other proc like PROC SQL to customize your report.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Otherwise, you could get rid of missing value from your dataset.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 01:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948847#M371212</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-24T01:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948932#M371243</link>
      <description>&lt;P&gt;Yes, I want to keep all observations. If Client A is missing race but has gender, I still want to count their gender. But when I print the table, I don't want a "missing" category to show under race. I agree this might not make sense, but it's what I was asked to create&amp;nbsp;&lt;SPAN&gt;¯\_(ツ)_/¯&amp;nbsp; If proc tabulate won't work, I'll try proc sql to restructure the data.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 16:27:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948932#M371243</guid>
      <dc:creator>lml819</dc:creator>
      <dc:date>2024-10-24T16:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948933#M371244</link>
      <description>&lt;P&gt;Thank you for the suggestion! I'll try creating an output dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 16:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948933#M371244</guid>
      <dc:creator>lml819</dc:creator>
      <dc:date>2024-10-24T16:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948993#M371267</link>
      <description>Yeah. If you don't want to print MISSING value, try PROC SQL which is most convenient and useful tool to build a report.</description>
      <pubDate>Fri, 25 Oct 2024 01:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/948993#M371267</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-25T01:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949003#M371273</link>
      <description>&lt;P&gt;OK. If I understand what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.heart(obs=200);
run;

proc sql;
create table report as
select 'DeathCause' as a,' '||DeathCause as b,sex as c,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where DeathCause is not missing
   group by DeathCause,Sex
union all
select 'DeathCause' ,'SubTotal',sex,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where sex is not missing 
   group by sex

union all

select 'bp_status' as a,' '||bp_status as b,sex as c,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where bp_status is not missing
   group by bp_status,Sex
union all
select 'bp_status' ,'SubTotal',sex,
 count(*) as _n label='No.',
 100*calculated _n/(select count(*) from have where Sex=a.Sex) as p format=8.2 label='%'
 from have as a
  where sex is not missing
   group by sex
;
quit;



proc report data=report nowd;
columns a b c,(_n p);
define a/group noprint;
define b/group '';
define c/across '';
compute before a/style={just=l};
line a $40.;
endcomp;
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_0-1729828063250.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101803i3A882398B4129528/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1729828063250.png" alt="Ksharp_0-1729828063250.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 03:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949003#M371273</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-25T03:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949026#M371287</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/470632"&gt;@lml819&lt;/a&gt;&amp;nbsp;You could just exclude the missings from the source data using one of below two options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you can't do with Proc Tabulate is to then include the missings for the last total line. That's imho also really hard to understand and somewhat illogical.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1729849254773.png" style="width: 678px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101807iE85AD05AA6844925/image-dimensions/678x189?v=v2" width="678" height="189" role="button" title="Patrick_0-1729849254773.png" alt="Patrick_0-1729849254773.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1729849457087.png" style="width: 641px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101808i5B2E2A6FB76BED76/image-dimensions/641x213?v=v2" width="641" height="213" role="button" title="Patrick_1-1729849457087.png" alt="Patrick_1-1729849457087.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 09:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949026#M371287</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-25T09:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate: show subtotals by variable and suppress missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949039#M371295</link>
      <description>&lt;P&gt;This is it! Thank you, I appreciate your time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 14:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-show-subtotals-by-variable-and-suppress-missing/m-p/949039#M371295</guid>
      <dc:creator>lml819</dc:creator>
      <dc:date>2024-10-25T14:07:38Z</dc:date>
    </item>
  </channel>
</rss>

