<?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 How to count/add occurrences of variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44980#M11845</link>
    <description>Does anyone have an idea how I would add up the number of occurrences of a variable and put them into a group? Here's a sample of the dataset I'm working with:&lt;BR /&gt;
&lt;BR /&gt;
                              DATE    CASENUMBER    CODE    STATUS    MEM         NAM    TIM&lt;BR /&gt;
&lt;BR /&gt;
                                100629    CASE1665       CPL       AVER     ABC    AAA    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.3&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    CCC    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    AAA    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    DDD    0.2&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      AAA    2.0&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      EEE    1.0&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      EEE    5.0&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     AAA    0.5&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     AAA    0.2&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     CCC    0.2&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    BBB    1.0&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    AAA   0.3&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    AAA    0.2&lt;BR /&gt;
                                100630    CASE1669       RLT       ADOC    XEL      AAA    0.5&lt;BR /&gt;
&lt;BR /&gt;
What I want is a sum of unique occurrence of the code field based on CASENUMBER. I've tried PROC FREQ as well as counters and using nested if statements and LAST.CODE but I always end up with an addition of all occurrences. For example using counters or PROC FREQ i end up with RLT = 13 but what i'm looking for is RLT = 4 because there are only 4 unique cases. Any suggestions?</description>
    <pubDate>Wed, 07 Jul 2010 01:22:36 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-07-07T01:22:36Z</dc:date>
    <item>
      <title>How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44980#M11845</link>
      <description>Does anyone have an idea how I would add up the number of occurrences of a variable and put them into a group? Here's a sample of the dataset I'm working with:&lt;BR /&gt;
&lt;BR /&gt;
                              DATE    CASENUMBER    CODE    STATUS    MEM         NAM    TIM&lt;BR /&gt;
&lt;BR /&gt;
                                100629    CASE1665       CPL       AVER     ABC    AAA    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.3&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1663       DYS       ADOC    DEF     BBB    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    CCC    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    AAA    0.2&lt;BR /&gt;
                                100629    CASE1661       RLT       AVER     GHI    DDD    0.2&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      AAA    2.0&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      EEE    1.0&lt;BR /&gt;
                                100629    CASE1666       RLT       ASOL     JKL      EEE    5.0&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     AAA    0.5&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     AAA    0.2&lt;BR /&gt;
                                100630    CASE1667       RLT       AANS     MNL     CCC    0.2&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    BBB    1.0&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    AAA   0.3&lt;BR /&gt;
                                100630    CASE1668       RLT       ASOL     DE1    AAA    0.2&lt;BR /&gt;
                                100630    CASE1669       RLT       ADOC    XEL      AAA    0.5&lt;BR /&gt;
&lt;BR /&gt;
What I want is a sum of unique occurrence of the code field based on CASENUMBER. I've tried PROC FREQ as well as counters and using nested if statements and LAST.CODE but I always end up with an addition of all occurrences. For example using counters or PROC FREQ i end up with RLT = 13 but what i'm looking for is RLT = 4 because there are only 4 unique cases. Any suggestions?</description>
      <pubDate>Wed, 07 Jul 2010 01:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44980#M11845</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-07T01:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44981#M11846</link>
      <description>Hi:&lt;BR /&gt;
  Just looking at your data, I wonder why RLT is not equal to 5. I see that RLT occurs in the following cases: 1661, 1666, 1667, 1668 and 1669.  I can see how PROC FREQ would come up with RLT=13, because the code, RLT, occurs a total of 13 times in the entire file. Is there another criteria other than CASENUMBER and CODE that determines what consititutes a "unique" case??&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 07 Jul 2010 01:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44981#M11846</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-07T01:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44982#M11847</link>
      <description>Having made a lot of assumptions below may be what you want:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create view V_DCS as&lt;BR /&gt;
    select Distinct CODE, STATUS&lt;BR /&gt;
      from have&lt;BR /&gt;
   ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
options missing=' ';&lt;BR /&gt;
proc tabulate data=V_DCS noseps format=8.;&lt;BR /&gt;
  class Code Status;&lt;BR /&gt;
  keylabel n=' ' all='Total';&lt;BR /&gt;
  table Code ,Status all;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Wed, 07 Jul 2010 06:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44982#M11847</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-07-07T06:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44983#M11848</link>
      <description>Hi.Patrick&lt;BR /&gt;
there is only one sql statement can do this.&lt;BR /&gt;
Assuming the last obs is 1668.&lt;BR /&gt;
So code:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input (DATE CASENUMBER CODE STATUS MEM NAM TIM) ($);&lt;BR /&gt;
&lt;BR /&gt;
datalines;&lt;BR /&gt;
100629 CASE1665 CPL AVER ABC AAA 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.3&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI CCC 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI AAA 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI DDD 0.2&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL AAA 2.0&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL EEE 1.0&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL EEE 5.0&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL AAA 0.5&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL AAA 0.2&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL CCC 0.2&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 BBB 1.0&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 AAA 0.3&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 AAA 0.2&lt;BR /&gt;
100630 CASE1668 RLT ADOC XEL AAA 0.5&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql feedback;&lt;BR /&gt;
select code,count(distinct CASENUMBER) label='Freq'&lt;BR /&gt;
 from temp&lt;BR /&gt;
 group by CODE&lt;BR /&gt;
 ;&lt;BR /&gt;
quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 07 Jul 2010 12:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44983#M11848</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-07-07T12:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44984#M11849</link>
      <description>Hi Cynthia - I'm sorry yes you're right RLT should be 5, DYS should be 1 and CPL should 1. The only unique identifier is the CASENUMBER. I was hoping to be able to use some kind of counter and FIRST.PRODUCT and LAST.PRODUCT with some IF statements but I'm not sure if that's do-able.&lt;BR /&gt;
&lt;BR /&gt;
Hi Ksharp - That's great that's actually the results that I'm looking for. I've never used proc sql before though and was wondering if there's a way to group together codes into 2 'buckets'? For example CPL and RLT into bucket 1 and DYS into bucket 2 so I would end up with bucket 1 = 6 and bucket 2 = 1&lt;BR /&gt;
&lt;BR /&gt;
Also is there a reason that you said 'Assuming the last obs is 1668.' ? Would the last obs "100630 CASE1669 RLT ADOC XEL AAA 0.5" cause an issue? &lt;BR /&gt;
&lt;BR /&gt;
Thanks everyone,&lt;BR /&gt;
japena</description>
      <pubDate>Wed, 07 Jul 2010 15:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44984#M11849</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-07T15:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44985#M11850</link>
      <description>Hi:&lt;BR /&gt;
  It is do-able with FIRST. processing...but not exactly the way you think. Conceptually, it would go like this:&lt;BR /&gt;
1) create a dataset with the unique combos of CaseNumber and Code (use either DATA step program or PROC SQL -- essentially get just one obs for each CaseNumber/Code combo)  &lt;BR /&gt;
2) pass this newly created dataset to PROC FREQ to get your counts (or if you ONLY want counts, then use a PROC SQL step to just select distnct)&lt;BR /&gt;
&lt;BR /&gt;
To answer your question about how to set buckets, I would do this in a user-defined format (although you could do this in the DATA step or PROC SQL, too).&lt;BR /&gt;
&lt;BR /&gt;
I show these techniques in the program below.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
                &lt;BR /&gt;
** read the data;&lt;BR /&gt;
data cases;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input DATE :yymmdd6. CASENUMBER $ CODE $ STATUS $ MEM $ NAM $ TIM;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100629 CASE1665 CPL AVER ABC AAA 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.3&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1663 DYS ADOC DEF BBB 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI CCC 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI AAA 0.2&lt;BR /&gt;
100629 CASE1661 RLT AVER GHI DDD 0.2&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL AAA 2.0&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL EEE 1.0&lt;BR /&gt;
100629 CASE1666 RLT ASOL JKL EEE 5.0&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL AAA 0.5&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL AAA 0.2&lt;BR /&gt;
100630 CASE1667 RLT AANS MNL CCC 0.2&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 BBB 1.0&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 AAA 0.3&lt;BR /&gt;
100630 CASE1668 RLT ASOL DE1 AAA 0.2&lt;BR /&gt;
100630 CASE1669 RLT ADOC XEL AAA 0.5&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
proc sort data=cases;&lt;BR /&gt;
  by  casenumber code;&lt;BR /&gt;
run;&lt;BR /&gt;
               &lt;BR /&gt;
** create output dataset with unique occurrences of casenumber and code;&lt;BR /&gt;
data countcode(keep=casenumber code);&lt;BR /&gt;
  set cases;&lt;BR /&gt;
  by  casenumber code;&lt;BR /&gt;
  if first.code then output;&lt;BR /&gt;
run;&lt;BR /&gt;
                      &lt;BR /&gt;
/*&lt;BR /&gt;
** Make dataset with PROC SQL instead of FIRST. logic;&lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
     create table countcode2 as&lt;BR /&gt;
     select distinct casenumber, code &lt;BR /&gt;
     from cases &lt;BR /&gt;
     order by CODE ;&lt;BR /&gt;
quit;&lt;BR /&gt;
                            &lt;BR /&gt;
proc print data=countcode2;&lt;BR /&gt;
  title 'This is the same data as in CountCode dataset';&lt;BR /&gt;
ods listing close;&lt;BR /&gt;
*/&lt;BR /&gt;
                                            &lt;BR /&gt;
ods listing close;&lt;BR /&gt;
ods html file='c:\temp\countcode.html' style=sasweb;&lt;BR /&gt;
** show what is in dataset created above;&lt;BR /&gt;
proc print data=countcode;&lt;BR /&gt;
  title 'What is in Dataset CountCode -- Unique combos of CaseNumber and Code';&lt;BR /&gt;
run;&lt;BR /&gt;
                       &lt;BR /&gt;
** now use proc freq on dataset created above;&lt;BR /&gt;
proc freq data=countcode;&lt;BR /&gt;
  title 'PROC FREQ on unique values of CaseNumber and Code';&lt;BR /&gt;
  tables code;&lt;BR /&gt;
run;&lt;BR /&gt;
                     &lt;BR /&gt;
** Create Buckets Label using PROC FORMAT;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value $bckt 'CPL', 'RLT' = 'Bucket 1'&lt;BR /&gt;
              'DYS' = 'Bucket 2'&lt;BR /&gt;
             other = 'Bucket Unknown';&lt;BR /&gt;
run; &lt;BR /&gt;
                     &lt;BR /&gt;
** Use $bckt format with PROC FREQ;&lt;BR /&gt;
proc freq data=countcode;&lt;BR /&gt;
  title 'PROC FREQ with $BCKT format';&lt;BR /&gt;
  tables code;&lt;BR /&gt;
  format code $bckt.;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
                     &lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 07 Jul 2010 21:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44985#M11850</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-07T21:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44986#M11851</link>
      <description>Cynthia, &lt;BR /&gt;
&lt;BR /&gt;
Thanks a lot exactly what I was looking for. I'll have to tweak it and play around it with it a little bit but this should get me a good start. I'm assuming that I can obtain the same output with listing instead of html? &lt;BR /&gt;
&lt;BR /&gt;
On a sort of related question regarding counters and LAST. I'm trying to get a variable with the total sum of TIM, I used a counter with an IF LAST THEN variable equal to tmp but it's not working so well for me. Something like this:&lt;BR /&gt;
&lt;BR /&gt;
DATA TIME;&lt;BR /&gt;
  SET TTIME;&lt;BR /&gt;
  RETAIN TMP 0;&lt;BR /&gt;
  TOTALTIME = 0;&lt;BR /&gt;
  IF NOT MISSING(TIM) THEN TMP = TMP + TIM;&lt;BR /&gt;
  IF LAST.CASENUMBER THEN TOTALTIME=TMP;&lt;BR /&gt;
&lt;BR /&gt;
PROC PRINT NOOBS;&lt;BR /&gt;
  TITLE 'TOTAL TIME';&lt;BR /&gt;
  VAR TOTALTIME;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
All I get is a bunch of "." vertically which represent each of the observations, if i print out the counter which is TMP in this case I can see the time been added up correctly except I'm only interested in the final value and printing the final value. Is there a more straight forward way to do this?</description>
      <pubDate>Thu, 08 Jul 2010 01:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44986#M11851</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-08T01:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44987#M11852</link>
      <description>Hi:&lt;BR /&gt;
  Well, without a BY statement, your logic will never work correctly. But if you ONLY want the final value (or grand total of TIM) to show, then why not use one of the SAS reporting procedures instead of using a DATA step program. There's no need to add everything up yourself if all you want is a grand total or even a breakdown by CASENUMBER and CODE.&lt;BR /&gt;
&lt;BR /&gt;
  However, my tendency would be to use either PROC MEANS, PROC REPORT or PROC TABULATE to get the total of the TIM variable. By default, missing values are ignored in the calculation of statistics, so the test for NOT MISSING is already taken care of when you use SAS procedures to generate statistics, such as summing.&lt;BR /&gt;
 &lt;BR /&gt;
  In the code below, I'm showing the PROC REPORT and PROC TABULATE and PROC MEANS methods. All 3 procedures will create and output dataset. PROC MEANS uses the OUTPUT statement, while PROC REPORT and PROC TABULATE both use the the OUT= option on the PROC statement. The reason I prefer PROC REPORT and PROC TABULATE over PROC MEANS is that I can get subtotals and grand totals in the same report with either REPORT and TABULATE and with PROC MEANS, a bit more processing would be required to get the CASENUMBER or CASENUMBER/CODE breakdown along with the GRAND TOTAL.&lt;BR /&gt;
&lt;BR /&gt;
  There is a lot of good documentation on all 3 of these procedures. I hope that the examples below will get you started.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
** Uses CASES data, as shown in my previous posting;&lt;BR /&gt;
ods listing;&lt;BR /&gt;
       &lt;BR /&gt;
proc report data=cases nowd;&lt;BR /&gt;
   title '1a) PROC REPORT get grand total only';&lt;BR /&gt;
   column tim;&lt;BR /&gt;
   define tim / sum "Time";&lt;BR /&gt;
run;&lt;BR /&gt;
                &lt;BR /&gt;
proc report data=cases nowd;&lt;BR /&gt;
   title '1b) PROC REPORT get case breakdown';&lt;BR /&gt;
   column casenumber tim;&lt;BR /&gt;
   define casenumber / group "Case";&lt;BR /&gt;
   define tim / sum "Time";&lt;BR /&gt;
   rbreak after / summarize;&lt;BR /&gt;
run;&lt;BR /&gt;
                      &lt;BR /&gt;
proc report data=cases nowd;&lt;BR /&gt;
   title '1c) PROC REPORT get case and code';&lt;BR /&gt;
   column casenumber code tim;&lt;BR /&gt;
   define casenumber / group "Case";&lt;BR /&gt;
   define code / group "Code";&lt;BR /&gt;
   define tim / sum "Time";&lt;BR /&gt;
   rbreak after / summarize;&lt;BR /&gt;
run;&lt;BR /&gt;
                 &lt;BR /&gt;
proc report data=cases nowd;&lt;BR /&gt;
   title '1d) PROC REPORT get code breakdown only';&lt;BR /&gt;
   column code tim;&lt;BR /&gt;
   define code / group "Code";&lt;BR /&gt;
   define tim / sum "Time";&lt;BR /&gt;
   rbreak after / summarize;&lt;BR /&gt;
run;&lt;BR /&gt;
              &lt;BR /&gt;
proc tabulate data=cases;&lt;BR /&gt;
  title '2a) PROC TABULATE get grand total only';&lt;BR /&gt;
  var tim;&lt;BR /&gt;
  table tim*sum;&lt;BR /&gt;
  label tim="Time";&lt;BR /&gt;
run;&lt;BR /&gt;
             &lt;BR /&gt;
proc tabulate data=cases;&lt;BR /&gt;
  title '2b) PROC TABULATE get casenumber breakdown';&lt;BR /&gt;
  class casenumber;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
  table casenumber all,&lt;BR /&gt;
        tim*sum;&lt;BR /&gt;
  label tim="Time" &lt;BR /&gt;
        casenumber="Case";&lt;BR /&gt;
run;&lt;BR /&gt;
                 &lt;BR /&gt;
proc tabulate data=cases;&lt;BR /&gt;
  title '2c) PROC TABULATE get casenumber and code breakdown';&lt;BR /&gt;
  class casenumber code;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
  table casenumber*code all,&lt;BR /&gt;
        tim*sum;&lt;BR /&gt;
  label tim="Time" &lt;BR /&gt;
        casenumber="Case"&lt;BR /&gt;
        code="Code";&lt;BR /&gt;
run;&lt;BR /&gt;
            &lt;BR /&gt;
proc tabulate data=cases;&lt;BR /&gt;
  title '2d) PROC TABULATE get code breakdown only';&lt;BR /&gt;
  class  code;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
  table code all,&lt;BR /&gt;
        tim*sum;&lt;BR /&gt;
  label tim="Time" &lt;BR /&gt;
        code="Code";&lt;BR /&gt;
run;&lt;BR /&gt;
                    &lt;BR /&gt;
proc means data=cases sum;&lt;BR /&gt;
  title '3a) Grand Total of TIM only';&lt;BR /&gt;
  var tim;&lt;BR /&gt;
run;&lt;BR /&gt;
                 &lt;BR /&gt;
proc means data=cases sum;&lt;BR /&gt;
  title '3b) PROC MEANS get casenumber breakdown';&lt;BR /&gt;
  class casenumber;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
run;&lt;BR /&gt;
         &lt;BR /&gt;
proc means data=cases sum;&lt;BR /&gt;
  title '3c) PROC MEANS get casenumber and code breakdown';&lt;BR /&gt;
  class casenumber code;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
run;&lt;BR /&gt;
                     &lt;BR /&gt;
proc means data=cases sum;&lt;BR /&gt;
  title '3d) PROC MEANS get code breakdown';&lt;BR /&gt;
  class code;&lt;BR /&gt;
  var tim;&lt;BR /&gt;
run;&lt;BR /&gt;
                &lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 08 Jul 2010 02:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44987#M11852</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-08T02:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44988#M11853</link>
      <description>Hi Ksharp&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Cheers&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 09 Jul 2010 02:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44988#M11853</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-07-09T02:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to count/add occurrences of variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44989#M11854</link>
      <description>Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
This should get me going thank you so much!</description>
      <pubDate>Fri, 09 Jul 2010 20:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-count-add-occurrences-of-variable/m-p/44989#M11854</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-09T20:16:40Z</dc:date>
    </item>
  </channel>
</rss>

