<?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 question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12184#M1581</link>
    <description>I am stuck.  I don't get any error messages yet SAS does not provide the aggreate sum of the three species. &lt;BR /&gt;
&lt;BR /&gt;
First, I already read in a spreadsheet into SAS with the weight of different species.  I called the data sarec.  I have over 4,000 records with 10 different species.   &lt;BR /&gt;
&lt;BR /&gt;
I defined my species and my aggregate of three of the species with the following proc format code:&lt;BR /&gt;
&lt;BR /&gt;
proc format data=sarec;&lt;BR /&gt;
   value $sp(multilabel notsorted)&lt;BR /&gt;
    'black grouper'='black grouper'&lt;BR /&gt;
    'red grouper'='red grouper'&lt;BR /&gt;
    'gag'='gag'&lt;BR /&gt;
    'black grouper','red grouper','gag'='Black, Red, and Gag grouper'&lt;BR /&gt;
    'golden tilefish'='golden tilefish'&lt;BR /&gt;
    'red snapper'='red snapper'&lt;BR /&gt;
    'snowy grouper'='snowy grouper'&lt;BR /&gt;
    'speckled hind'='speckled hind'&lt;BR /&gt;
    'vermillion snapper'='vermillion snapper'&lt;BR /&gt;
    'warsaw grouper'='warsaw grouper';&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
Then I added the format code to my proc tabulate with the code below.  new_com is the column in my dataset with the species names.  &lt;BR /&gt;
   &lt;BR /&gt;
    format new_com $sp.;&lt;BR /&gt;
&lt;BR /&gt;
The proc tabulate provided the sum of weights for each species but did not provide a sum of weights of my three species aggregate (Black, Gag, and Red grouper).  &lt;BR /&gt;
&lt;BR /&gt;
Any advice would be greatly appreciated.</description>
    <pubDate>Tue, 14 Jun 2011 18:37:46 GMT</pubDate>
    <dc:creator>megalops</dc:creator>
    <dc:date>2011-06-14T18:37:46Z</dc:date>
    <item>
      <title>Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12178#M1575</link>
      <description>I am learning SAS and this is my first post on the forum.  I hope I can crearly explain my problem.  &lt;BR /&gt;
&lt;BR /&gt;
I used Proc Tabulate to sum up the weight for a fish species.  It worked great, but I need to also add an aggregate sum of two of the species.  Here is the layout of the table that I already have:    &lt;BR /&gt;
&lt;BR /&gt;
species    weight&lt;BR /&gt;
X                25&lt;BR /&gt;
Y               20&lt;BR /&gt;
Z               34&lt;BR /&gt;
&lt;BR /&gt;
I want to add an extra row.  Here is a layout of the table that I want:  &lt;BR /&gt;
&lt;BR /&gt;
species    weight&lt;BR /&gt;
X                25&lt;BR /&gt;
Y               20&lt;BR /&gt;
Z               34&lt;BR /&gt;
X+Y           45&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
The problem is that I don't know how to get proc tabulate to add the extra row of specis X and Y.  I am assuming I need to add something to the tables statement of the procedure but I am not sure.  &lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated.</description>
      <pubDate>Mon, 13 Jun 2011 14:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12178#M1575</guid>
      <dc:creator>megalops</dc:creator>
      <dc:date>2011-06-13T14:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12179#M1576</link>
      <description>You can do that with a multilabel format.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data fish;&lt;BR /&gt;
   input species:$1. weight;&lt;BR /&gt;
   cards;&lt;BR /&gt;
X 25&lt;BR /&gt;
Y 20&lt;BR /&gt;
Z 34&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc format;&lt;BR /&gt;
   value $sp(multilabel notsorted)&lt;BR /&gt;
    'X'='X'&lt;BR /&gt;
    'Y'='Y'&lt;BR /&gt;
    'Z'='Z'&lt;BR /&gt;
    'X','Y'='X+Y';&lt;BR /&gt;
   run;&lt;BR /&gt;
proc tabulate;&lt;BR /&gt;
   class species / mlf order=data preloadfmt;&lt;BR /&gt;
   format species $sp.;&lt;BR /&gt;
   var weight;&lt;BR /&gt;
   tables species,weight*sum;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 13 Jun 2011 14:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12179#M1576</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-13T14:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12180#M1577</link>
      <description>I am sorry, I am struggling with the multilabel format.  &lt;BR /&gt;
&lt;BR /&gt;
Is there some text I can add to the tables statement telling sas to do an additional sum of only certain species?</description>
      <pubDate>Mon, 13 Jun 2011 15:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12180#M1577</guid>
      <dc:creator>megalops</dc:creator>
      <dc:date>2011-06-13T15:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12181#M1578</link>
      <description>When formats are used on the CLASS variables the groupings are controlled by the format and no specification is needed in the table statement.&lt;BR /&gt;
If you actually need to create more groups than your example then add them to the FORMAT used for the CLASS variable.</description>
      <pubDate>Mon, 13 Jun 2011 16:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12181#M1578</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-06-13T16:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12182#M1579</link>
      <description>The multilabel format is not the only option.  You can create "new" species that are the combinations you want.&lt;BR /&gt;
&lt;BR /&gt;
Give more info regarding your specific needs.</description>
      <pubDate>Mon, 13 Jun 2011 17:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12182#M1579</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-06-13T17:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12183#M1580</link>
      <description>Hi:&lt;BR /&gt;
  Multilabel formats were designed for exactly this purpose. For example, given your data, look what happens when a TOTAL and a percent are added:&lt;BR /&gt;
[pre]&lt;BR /&gt;
+-------------------------------------------------+&lt;BR /&gt;
|                       |         weight          |&lt;BR /&gt;
|                       +-------------------------+&lt;BR /&gt;
|                       |    Sum     |   PctSum   |&lt;BR /&gt;
+-----------------------+------------+------------+&lt;BR /&gt;
|species                |            |            |&lt;BR /&gt;
+-----------------------+            |            |&lt;BR /&gt;
|X                      |       25.00|       31.65|&lt;BR /&gt;
+-----------------------+------------+------------+&lt;BR /&gt;
|Y                      |       20.00|       25.32|&lt;BR /&gt;
+-----------------------+------------+------------+&lt;BR /&gt;
|Z                      |       34.00|       43.04|&lt;BR /&gt;
+-----------------------+------------+------------+&lt;BR /&gt;
|X+Y                    |       45.00|       56.96|&lt;BR /&gt;
+-----------------------+------------+------------+&lt;BR /&gt;
|All                    |       79.00|      100.00|&lt;BR /&gt;
+-------------------------------------------------+&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                            &lt;BR /&gt;
The nice thing about using multi-lable formats is that X+Y can be taken into account without having an impact on the overall N or Count of 79. &lt;BR /&gt;
&lt;BR /&gt;
Multi-label formats are not difficult -- it's a matter of knowing when to use them. My rule of thumb is whether I need "double-counting" -- where I want to count an observation in the category based on one class (such as the individual X and Y values), but then I also want to "double-count" the X+Y together--that's when to design a multi-label format. But designing the multilabel format is only half the battle, you design the format with PROC FORMAT, using the options (multilabel notsorted). Then you have to USE the format inside PROC TABULATE with the MLF and PRELOADFMT on your CLASS statement.&lt;BR /&gt;
 &lt;BR /&gt;
Many folks can work with TABULATE a long time and never run into the need for multilabel formats. There is nothing you can specify in the TABLE statement to sum X+Y on the report.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 13 Jun 2011 18:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12183#M1580</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-06-13T18:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12184#M1581</link>
      <description>I am stuck.  I don't get any error messages yet SAS does not provide the aggreate sum of the three species. &lt;BR /&gt;
&lt;BR /&gt;
First, I already read in a spreadsheet into SAS with the weight of different species.  I called the data sarec.  I have over 4,000 records with 10 different species.   &lt;BR /&gt;
&lt;BR /&gt;
I defined my species and my aggregate of three of the species with the following proc format code:&lt;BR /&gt;
&lt;BR /&gt;
proc format data=sarec;&lt;BR /&gt;
   value $sp(multilabel notsorted)&lt;BR /&gt;
    'black grouper'='black grouper'&lt;BR /&gt;
    'red grouper'='red grouper'&lt;BR /&gt;
    'gag'='gag'&lt;BR /&gt;
    'black grouper','red grouper','gag'='Black, Red, and Gag grouper'&lt;BR /&gt;
    'golden tilefish'='golden tilefish'&lt;BR /&gt;
    'red snapper'='red snapper'&lt;BR /&gt;
    'snowy grouper'='snowy grouper'&lt;BR /&gt;
    'speckled hind'='speckled hind'&lt;BR /&gt;
    'vermillion snapper'='vermillion snapper'&lt;BR /&gt;
    'warsaw grouper'='warsaw grouper';&lt;BR /&gt;
    run;&lt;BR /&gt;
&lt;BR /&gt;
Then I added the format code to my proc tabulate with the code below.  new_com is the column in my dataset with the species names.  &lt;BR /&gt;
   &lt;BR /&gt;
    format new_com $sp.;&lt;BR /&gt;
&lt;BR /&gt;
The proc tabulate provided the sum of weights for each species but did not provide a sum of weights of my three species aggregate (Black, Gag, and Red grouper).  &lt;BR /&gt;
&lt;BR /&gt;
Any advice would be greatly appreciated.</description>
      <pubDate>Tue, 14 Jun 2011 18:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12184#M1581</guid>
      <dc:creator>megalops</dc:creator>
      <dc:date>2011-06-14T18:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12185#M1582</link>
      <description>Hi:&lt;BR /&gt;
  I can think of a few things:&lt;BR /&gt;
1) did you modify the CLASS statement with MLF and PRELOADFMT???&lt;BR /&gt;
 &lt;BR /&gt;
2) the format will ONLY work for 'black grouper' for example -- it will not work for Black grouper or Black Grouper or black Grouper -- so whatever is in your data is how you should specify the species name in the format. If the data are not standard, you might want to explicitly uppercase all the species when you read the values and the use uppercase in the format.&lt;BR /&gt;
 &lt;BR /&gt;
3) to see the total N, as I showed, you would use the keyword ALL in your TABLE statement&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 14 Jun 2011 19:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12185#M1582</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-06-14T19:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12186#M1583</link>
      <description>My bad.  I do get an error message.  The message says: &lt;BR /&gt;
&lt;BR /&gt;
ERROR 22-322: Syntax error, expecting one of the following: ;, ALLDUPS, CNTLIN, CNTLOUT, DDNAME,FMTLIB, INDD, LIB, LIBRARY, MAXLABLEN, MAXSELEN, NOREPLACE, NOTEXT82, OUT, OUTDD,PAGE.&lt;BR /&gt;
&lt;BR /&gt;
ERROR 76-322: Syntax error, statement will be ignored.&lt;BR /&gt;
&lt;BR /&gt;
I believe the error is comming from the following line of code:  &lt;BR /&gt;
&lt;BR /&gt;
value $sp(multilabel notsorted)&lt;BR /&gt;
&lt;BR /&gt;
I do not understand what $sp(multilabel notsorted) means.  Is the (multilabel notsorted) a note that should be excluded from the code?</description>
      <pubDate>Tue, 14 Jun 2011 20:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12186#M1583</guid>
      <dc:creator>megalops</dc:creator>
      <dc:date>2011-06-14T20:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12187#M1584</link>
      <description>PROC FORMAT does not take a DATA= option. If you compare your code to the PROC FORMAT code posted previously, you should see that there is no DATA= specified.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 14 Jun 2011 20:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12187#M1584</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-06-14T20:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12188#M1585</link>
      <description>Also order of definition in the value section of proc format statements makes a difference in output.&lt;BR /&gt;
&lt;BR /&gt;
Please see an example below.&lt;BR /&gt;
&lt;BR /&gt;
/* a further example with multilabel formats       */&lt;BR /&gt;
/* the indents are just to show the desired levels */&lt;BR /&gt;
/* I think that the order the statements occur in  */&lt;BR /&gt;
/* format may have an affect based on the options  */&lt;BR /&gt;
/* in Proc Tabulate. The spaces in the label are   */&lt;BR /&gt;
/* actually character 255 (Alt+255 on numeric pad) */&lt;BR /&gt;
/* Motor and Water are in that order to show that  */&lt;BR /&gt;
/* the output order is sorted in the manner we want*/&lt;BR /&gt;
/* not by the text of the responses                */&lt;BR /&gt;
/* (at least one case below )                      */&lt;BR /&gt;
&lt;BR /&gt;
proc format library=work;&lt;BR /&gt;
   value accidentl (multilabel notsorted)&lt;BR /&gt;
   1-5 = 'Accidents'&lt;BR /&gt;
      1-3 = '&amp;nbsp;Transport accidents'&lt;BR /&gt;
         1 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Motor vehicle accidents'&lt;BR /&gt;
         2 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Water, air, and space'&lt;BR /&gt;
         3 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Other land transport accidents'&lt;BR /&gt;
      4-5 = '&amp;nbsp;Nontransport accidents'&lt;BR /&gt;
         5 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Fishing'&lt;BR /&gt;
      ;&lt;BR /&gt;
   value accidentr (multilabel notsorted)&lt;BR /&gt;
   1-5 = 'Accidents'&lt;BR /&gt;
      1-3 = '&amp;nbsp;Transport accidents'&lt;BR /&gt;
      4-5 = '&amp;nbsp;Nontransport accidents'&lt;BR /&gt;
         1 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Motor vehicle accidents'&lt;BR /&gt;
         2 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Water, air, and space'&lt;BR /&gt;
         3 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Other land transport accidents'&lt;BR /&gt;
         5 = '&amp;nbsp;&amp;nbsp;&amp;nbsp;Fishing'&lt;BR /&gt;
      ;&lt;BR /&gt;
   value mf&lt;BR /&gt;
   1 = "Male"&lt;BR /&gt;
   2 = "Female"&lt;BR /&gt;
   ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* populate a dataset to display */&lt;BR /&gt;
/* This specifically does NOT generate any data for FISHING above*/&lt;BR /&gt;
/* to display the behavior of the options below in those cases.  */&lt;BR /&gt;
data junk;  &lt;BR /&gt;
   do i=1 to 50;&lt;BR /&gt;
      type = round(4*ranuni(1234)+.5);&lt;BR /&gt;
      sex  = round(2*ranuni(3455)+.5);&lt;BR /&gt;
      output;&lt;BR /&gt;
   end; &lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Notice that before we get here the data is NOT sorted */&lt;BR /&gt;
/* in any manner!!!!                                     */&lt;BR /&gt;
&lt;BR /&gt;
proc tabulate data=junk order=data;&lt;BR /&gt;
   class type / mlf PRELOADFMT;&lt;BR /&gt;
   class sex;&lt;BR /&gt;
   table type=' ', all='Total'*n=' '*f=comma9. sex=' '*n=' '*f=comma8.&lt;BR /&gt;
     /rts=35 printmiss misstext='0';&lt;BR /&gt;
   format type accidentl. sex mf.;&lt;BR /&gt;
   title 'Option Order=Data Preloadfmt Printmiss Misstext=0 format accidentl';&lt;BR /&gt;
run;&lt;BR /&gt;
proc tabulate data=junk order=data;&lt;BR /&gt;
   class type / mlf PRELOADFMT;&lt;BR /&gt;
   class sex;&lt;BR /&gt;
   table type=' ', all='Total'*n=' '*f=comma9. sex=' '*n=' '*f=comma8.&lt;BR /&gt;
     /rts=35 printmiss misstext='0';&lt;BR /&gt;
   format type accidentr. sex mf.;&lt;BR /&gt;
   title 'Option Order=Data Preloadfmt Printmiss Misstext=0  format accidentr';&lt;BR /&gt;
run;&lt;BR /&gt;
title;</description>
      <pubDate>Tue, 14 Jun 2011 22:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-tabulate-question/m-p/12188#M1585</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-06-14T22:49:38Z</dc:date>
    </item>
  </channel>
</rss>

