<?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 TABULATE NOT COUNTING CORRECTLY in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/TABULATE-NOT-COUNTING-CORRECTLY/m-p/40155#M10383</link>
    <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I have a table with 376k records. I am using the following PROC Tabulate to count the number of records per a particular variable. The following is the  results of the log;&lt;BR /&gt;
&lt;BR /&gt;
2682  PROC TABULATE DATA=PICreditHire missing;&lt;BR /&gt;
2683  CLASS FIRST_PI_RESDATE;&lt;BR /&gt;
2684  VAR CreditHireTotal;&lt;BR /&gt;
2685  TABLE FIRST_PI_RESDATE,CreditHireTotal*(N='NbrOfClaims');&lt;BR /&gt;
2686  Title;&lt;BR /&gt;
2687  RUN;&lt;BR /&gt;
NOTE: There were 376842 observations read from the data set &lt;BR /&gt;
&lt;BR /&gt;
However when I sum up the 'NbrOfClaims' field in the resulting output I only get 347k claims, despire the fact that the Tabulate has (correctly) read 376k claims from the source dataset. I've messed round with the MISSING options and eyeballed the source dataset and can't understand why Tabulate is missing some of the records. I've also tried using the PROC FREQ (below) and that has given me the correct results (376k records) as has taking the dataset into MS Access and running a count from there.&lt;BR /&gt;
&lt;BR /&gt;
PROC FREQ DATA-PICreditHire;&lt;BR /&gt;
TABLES FIRST_PI_RESDATE;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Any ideas why PROC TABULATE isn't picking up all the records in the count? I can't use PROC FREQ because I need to have some other analysis in the report (i.e. SUM) I've just reduced it to a Count on this post to make it easier to read.

The problem appears to be that the TABULATE is not including some of the values of 'CreditHireTotal' (Number, Length 8), which is why the PROC freq works as that is just a count against the FIRST_PI_RESDATE. From eyeballing I can't find any values that look strange and if I use CreditHireTotal as the Class variable and count against that I get a full count of the records (376k).&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: RobH</description>
    <pubDate>Tue, 19 Aug 2008 14:40:02 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-08-19T14:40:02Z</dc:date>
    <item>
      <title>TABULATE NOT COUNTING CORRECTLY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/TABULATE-NOT-COUNTING-CORRECTLY/m-p/40155#M10383</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I have a table with 376k records. I am using the following PROC Tabulate to count the number of records per a particular variable. The following is the  results of the log;&lt;BR /&gt;
&lt;BR /&gt;
2682  PROC TABULATE DATA=PICreditHire missing;&lt;BR /&gt;
2683  CLASS FIRST_PI_RESDATE;&lt;BR /&gt;
2684  VAR CreditHireTotal;&lt;BR /&gt;
2685  TABLE FIRST_PI_RESDATE,CreditHireTotal*(N='NbrOfClaims');&lt;BR /&gt;
2686  Title;&lt;BR /&gt;
2687  RUN;&lt;BR /&gt;
NOTE: There were 376842 observations read from the data set &lt;BR /&gt;
&lt;BR /&gt;
However when I sum up the 'NbrOfClaims' field in the resulting output I only get 347k claims, despire the fact that the Tabulate has (correctly) read 376k claims from the source dataset. I've messed round with the MISSING options and eyeballed the source dataset and can't understand why Tabulate is missing some of the records. I've also tried using the PROC FREQ (below) and that has given me the correct results (376k records) as has taking the dataset into MS Access and running a count from there.&lt;BR /&gt;
&lt;BR /&gt;
PROC FREQ DATA-PICreditHire;&lt;BR /&gt;
TABLES FIRST_PI_RESDATE;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
Any ideas why PROC TABULATE isn't picking up all the records in the count? I can't use PROC FREQ because I need to have some other analysis in the report (i.e. SUM) I've just reduced it to a Count on this post to make it easier to read.

The problem appears to be that the TABULATE is not including some of the values of 'CreditHireTotal' (Number, Length 8), which is why the PROC freq works as that is just a count against the FIRST_PI_RESDATE. From eyeballing I can't find any values that look strange and if I use CreditHireTotal as the Class variable and count against that I get a full count of the records (376k).&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: RobH</description>
      <pubDate>Tue, 19 Aug 2008 14:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/TABULATE-NOT-COUNTING-CORRECTLY/m-p/40155#M10383</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-19T14:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: TABULATE NOT COUNTING CORRECTLY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/TABULATE-NOT-COUNTING-CORRECTLY/m-p/40156#M10384</link>
      <description>Hi:&lt;BR /&gt;
  By default, when you cross an analysis variable with a statistic, missing values are ignored in the calculation of statistics. I'm guessing that you have several observations with missing values for the "CreditHireTotal" variable.&lt;BR /&gt;
&lt;BR /&gt;
If you run the code below, you will see that a copy of SASHELP.CLASS has been altered so that the value the SEX variable for 2 people has been changed and 2 heights have been turned to missing. The MISSING option reveals the 2 missing obs for the SEX variable, but has no effect on the count when it's based on (crossed with) height. The TABULATE program shows the difference between asking for the simple N and asking for the N crossed with the analysis variable.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
              &lt;BR /&gt;
data class;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  if name = 'Alfred' or name = 'Alice'&lt;BR /&gt;
     then sex = ' ';&lt;BR /&gt;
  else if _n_ gt 17 then height=.;&lt;BR /&gt;
run;&lt;BR /&gt;
                     &lt;BR /&gt;
proc print data=class;&lt;BR /&gt;
title 'note missing values';&lt;BR /&gt;
run;&lt;BR /&gt;
                   &lt;BR /&gt;
proc freq data=class;&lt;BR /&gt;
  tables sex height / nocum nopercent;&lt;BR /&gt;
run;&lt;BR /&gt;
                 &lt;BR /&gt;
PROC TABULATE DATA=class missing;&lt;BR /&gt;
  CLASS sex;&lt;BR /&gt;
  VAR height;&lt;BR /&gt;
  TABLE sex='Gender' all,&lt;BR /&gt;
        height*(N='NbrOfStudents') / box='Ex 1';&lt;BR /&gt;
                   &lt;BR /&gt;
  table sex='Gender' all,&lt;BR /&gt;
        n='NbrOfStudents' / box='Ex 2';&lt;BR /&gt;
                       &lt;BR /&gt;
  table sex='Gender' all,&lt;BR /&gt;
        n='Total count' height*N='non missing heights' &lt;BR /&gt;
        / box='Ex 3';&lt;BR /&gt;
  Title;&lt;BR /&gt;
RUN;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 19 Aug 2008 15:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/TABULATE-NOT-COUNTING-CORRECTLY/m-p/40156#M10384</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-08-19T15:40:23Z</dc:date>
    </item>
  </channel>
</rss>

