<?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 with classdata statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541920#M149727</link>
    <description>&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Mar 2019 09:34:48 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-03-11T09:34:48Z</dc:date>
    <item>
      <title>proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541890#M149710</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using proc tabulate to create a summary table.&lt;/P&gt;
&lt;P&gt;I want to display also categories that have no values in the raw data .&lt;/P&gt;
&lt;P&gt;In this example I want to see also category "0&amp;lt;-0.5" that has no values in the raw data.&lt;/P&gt;
&lt;P&gt;For this task I am using classdata statement.&lt;/P&gt;
&lt;P&gt;However, I get an error &amp;nbsp;"&amp;nbsp;Class variable Y_Category was not found in the preload data set or was incompatible with the primary data set variable of the same name.*&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data rawdata;
Input ID Y;
cards;
1 12000
2 0
3 0.6
4 0.7
5 19
6 90
7 200
8 400
9 800
10 2000
11 4000
12 9000
13 0
;
run;

proc format;
value FFmt
0='0'
0&amp;lt;-0.5='0&amp;lt;-0.5'
0.5&amp;lt;-20='0.5&amp;lt;-20'
20&amp;lt;-10000='5000&amp;lt;-10000'
10000-high='10000+';
Run;

data tbl2;
set rawdata;
Y_Category=put(Y,FFmt.);
format Y_Category $20.;
Run;
 

Data level;
Input Y_Category $20.;
cards;
0
0&amp;lt;-0.5
5000&amp;lt;-10000
10000+
;
Run;

proc sort data=tbl2;by y;run;
 proc tabulate data=tbl2  classdata=level ;
var Y;
class Y_Category/ORDER=data  MISSING;
table Y_Category='',Y=''*N='Customers'
            Y=''*PCTN='PCT from Total Customers'
			Y=''*SUM='Sum Y'
            Y=''*COLPCTSUM='PCT from total Y' /RTS=25 PRINTMISS BOX='category of Y' CONDENSE;
Run;

 /*ERROR: Class variable Y_Category was not found in the preload data set or was incompatible with the primary data set variable of 
       the same name.*/
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 06:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541890#M149710</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T06:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541897#M149712</link>
      <description>&lt;P&gt;This is the result of your posted code:&lt;/P&gt;
&lt;PRE&gt;-----------------------------------------------------------------------------
|category of Y          |            |  PCT from  |            |            |
|                       |            |   Total    |            |  PCT from  |
|                       | Customers  | Customers  |   Sum Y    |  total Y   |
|-----------------------+------------+------------+------------+------------|
|0                      |        2.00|       15.38|        0.00|        0.00|
|-----------------------+------------+------------+------------+------------|
|0&amp;lt;-0.5                 |        0.00|        0.00|           .|           .|
|-----------------------+------------+------------+------------+------------|
|5000&amp;lt;-10000            |        7.00|       53.85|    16490.00|       57.84|
|-----------------------+------------+------------+------------+------------|
|10000+                 |        1.00|        7.69|    12000.00|       42.09|
|-----------------------+------------+------------+------------+------------|
|0.5&amp;lt;-20                |        3.00|       23.08|       20.30|        0.07|
-----------------------------------------------------------------------------
&lt;/PRE&gt;
&lt;P&gt;Ignoring the strange sort-order (caused by using a alphanumeric variable), what's the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 07:12:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541897#M149712</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-11T07:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541901#M149714</link>
      <description>&lt;P&gt;When I run the proc tabulate I get an error "Class variable Y_Category was not found in the preload data set or was incompatible with the primary data set variable of the same name"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc tabulate data=tbl2  classdata=level ;
var Y;
class Y_Category/ORDER=data  MISSING;
table Y_Category='',Y=''*N='Customers'
            Y=''*PCTN='PCT from Total Customers'
			Y=''*SUM='Sum Y'
            Y=''*COLPCTSUM='PCT from total Y' /RTS=25 PRINTMISS BOX='category of Y' CONDENSE;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 07:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541901#M149714</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T07:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541902#M149715</link>
      <description>&lt;P&gt;Maxim 3: Know Your Data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at Y_category in tbl2 and in level.&lt;/P&gt;
&lt;P&gt;Since the maximum string length in your format is 11, Y_Category is defined in tbl2 with that length (the format does NOT change that!)&lt;/P&gt;
&lt;P&gt;Reading it with a length of 20 for level causes the incompatibility.&lt;/P&gt;
&lt;P&gt;Optimize your two data steps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tbl2;
set rawdata;
Y_Category = put(Y,FFmt.);
run;
 
data level;
input Y_Category $11.;
cards;
0
0&amp;lt;-0.5
5000&amp;lt;-10000
10000+
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and the following code will run without problems:&lt;/P&gt;
&lt;PRE&gt;27         data tbl2;
28         set rawdata;
29         Y_Category = put(Y,FFmt.);
30         run;

NOTE: There were 13 observations read from the data set WORK.RAWDATA.
NOTE: The data set WORK.TBL2 has 13 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds
      

31         
32         data level;
33         input Y_Category $11.;
34         cards;

NOTE: The data set WORK.LEVEL has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.07 seconds
      cpu time            0.00 seconds
      
39         ;

40         run;
41         
42         proc sort data=tbl2;
43         by y;
44         run;

NOTE: There were 13 observations read from the data set WORK.TBL2.
2                                                          Das SAS System                               07:43 Monday, March 11, 2019

NOTE: The data set WORK.TBL2 has 13 observations and 3 variables.
NOTE: PROZEDUR SORT used (Total process time):
      real time           0.04 seconds
      cpu time            0.00 seconds
      

45         
46         proc tabulate data=tbl2 classdata=level ;
47         var Y;
48         class Y_Category / order=data missing;
49         table Y_Category='',Y=''*N='Customers'
50               Y=''*PCTN='PCT from Total Customers'
51         			Y=''*SUM='Sum Y'
52               Y=''*COLPCTSUM='PCT from total Y' / rts=25 printmiss box='category of Y' condense;
53         run;

NOTE: There were 13 observations read from the data set WORK.TBL2.
NOTE: There were 4 observations read from the data set WORK.LEVEL.
NOTE: The PROCEDURE TABULATE printed page 1.
NOTE: PROZEDUR TABULATE used (Total process time):
      real time           0.12 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 07:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541902#M149715</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T07:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541903#M149716</link>
      <description>&lt;P&gt;My fault, i automatically removed the format-statement in the data step creating tbl2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need classdata at all, just use preloadfmt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawdata;
   Input ID Y;
   cards;
1 12000
2 0
3 0.6
4 0.7
5 19
6 90
7 200
8 400
9 800
10 2000
11 4000
12 9000
13 0
;
run;

proc format;
   value FFmt
      0='0'
      0&amp;lt;-0.5='0&amp;lt;-0.5'
      0.5&amp;lt;-20='0.5&amp;lt;-20'
      20&amp;lt;-10000='5000&amp;lt;-10000'
      10000-high='10000+';
run;

data work.cloned;
   set rawdata;

   Y_Category = y;

   format y_category ffmt.;

run;


proc tabulate data=cloned missing;
   var Y;
   class Y_Category / order=data preloadfmt missing ;
   
   table Y_Category='',Y=''*N='Customers'
      Y=''*PCTN='PCT from Total Customers'
      Y=''*SUM='Sum Y'
      Y=''*COLPCTSUM='PCT from total Y' /RTS=25 PRINTMISS BOX='category of Y' CONDENSE;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Mar 2019 07:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541903#M149716</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-03-11T07:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541905#M149717</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need classdata at all, just use preloadfmt:&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is the better option, anyway.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 07:36:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541905#M149717</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T07:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541909#M149720</link>
      <description>&lt;P&gt;Perfect!&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;Two more question please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I see that the order of the categories in the output is not as I want .&lt;/P&gt;
&lt;P&gt;I want it to be in the following order:&lt;/P&gt;
&lt;P&gt;0&lt;BR /&gt;0&amp;lt;-0.5&lt;BR /&gt;5000&amp;lt;-10000&lt;BR /&gt;10000+&lt;/P&gt;
&lt;P&gt;What should I do in order to get it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also want to ask&amp;nbsp;Why "Sum Y" and "PCT from total Y" in category "0&amp;lt;-0.5" is getting null value (.) and not 0??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 08:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541909#M149720</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T08:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541912#M149721</link>
      <description>&lt;P&gt;Make your dataset LEVEL complete. As posted, it only has 4 observations, while the format has 5 entries.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 08:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541912#M149721</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T08:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541913#M149722</link>
      <description>&lt;P&gt;perfect&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I also want to ask&amp;nbsp;Why "Sum Y" and "PCT from total Y" in category "0&amp;lt;-0.5" is getting null value (.) and not 0??&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 08:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541913#M149722</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T08:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541914#M149723</link>
      <description>&lt;P&gt;Sorry. I don't understand what you mean&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 09:02:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541914#M149723</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T09:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541915#M149724</link>
      <description>&lt;P&gt;Still better: use the preloadfmt option, and have a separate format for your class variable that you use in the preloadfmt:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawdata;
input ID Y;
cards;
1 12000
2 0
3 0.6
4 0.7
5 19
6 90
7 200
8 400
9 800
10 2000
11 4000
12 9000
13 0
;
run;

proc format;
value category
  0="0"
  0&amp;lt;-0.5="1"
  0.5&amp;lt;-20="2"
  20&amp;lt;-10000="3"
  10000-high="4"
;
value FFmt
  0='0'
  1='0&amp;lt;-0.5'
  2='0.5&amp;lt;-20'
  3='5000&amp;lt;-10000'
  4='10000+'
;
run;

data tbl2;
set rawdata;
Y_Category = input(put(Y,category.),1.);
format y_category ffmt.;
run;

proc tabulate data=tbl2;
var Y;
class Y_Category / order=data preloadfmt;
table
  Y_Category='',
  Y=''*N='Customers'
  Y=''*PCTN='PCT from Total Customers'
	Y=''*SUM='Sum Y'
  Y=''*COLPCTSUM='PCT from total Y'
  / rts=25 printmiss box='category of Y' condense
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first format does the conversion, the second serves to create the complete list.&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;-----------------------------------------------------------------------------
|category of Y          |            |  PCT from  |            |            |
|                       |            |   Total    |            |  PCT from  |
|                       | Customers  | Customers  |   Sum Y    |  total Y   |
|-----------------------+------------+------------+------------+------------|
|0                      |        2.00|       15.38|        0.00|        0.00|
|-----------------------+------------+------------+------------+------------|
|0&amp;lt;-0.5                 |        0.00|        0.00|           .|           .|
|-----------------------+------------+------------+------------+------------|
|0.5&amp;lt;-20                |        3.00|       23.08|       20.30|        0.07|
|-----------------------+------------+------------+------------+------------|
|5000&amp;lt;-10000            |        7.00|       53.85|    16490.00|       57.84|
|-----------------------+------------+------------+------------+------------|
|10000+                 |        1.00|        7.69|    12000.00|       42.09|
-----------------------------------------------------------------------------
&lt;/PRE&gt;
&lt;P&gt;Because you use class (and not by), no sorting is needed&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 09:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541915#M149724</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T09:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541916#M149725</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry. I don't understand what you mean&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Compare your original proc format code (5 entries) with your data step code for dataset level (4 entries). The 5th category from the format which is not found in level is appended at the end of the tabulate output.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 09:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541916#M149725</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T09:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541917#M149726</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;perfect&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I also want to ask&amp;nbsp;Why "Sum Y" and "PCT from total Y" in category "0&amp;lt;-0.5" is getting null value (.) and not 0??&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because &lt;U&gt;no&lt;/U&gt; entries are found, the summation ends up as sum(.), and that creates a missing value.&lt;/P&gt;
&lt;P&gt;For reference, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
x1 = sum(.);
x2 = sum(0,.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need at least 1 non-missing value for the summation to be non-missing. Counts, OTOH, create a zero.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 09:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541917#M149726</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-11T09:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate with classdata statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541920#M149727</link>
      <description>&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2019 09:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-with-classdata-statement/m-p/541920#M149727</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-03-11T09:34:48Z</dc:date>
    </item>
  </channel>
</rss>

