<?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: Again problems with proc tabulate (totals and sub-totals) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647856#M193924</link>
    <description>&lt;P&gt;No worries&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So does the provided code meet your expectations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 May 2020 15:49:51 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-05-14T15:49:51Z</dc:date>
    <item>
      <title>Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647840#M193917</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hello everybody&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The longer I thik about my data, the more problems appear which I havent thought about before: I am dealing with data of crime suspects like the following sample data:&lt;/P&gt;&lt;PRE&gt;DATA suspects;
INPUT 	personId :4. 
		article:$3. 
		title:$20. 
		age:3. 
		sex :$1.
		residenceStatus :$1.
  		dateOfCrime : yymmdd10.;
FORMAT dateOfCrime yymmdd10.;
INFILE DATALINES DSD;
DATALINES;
10,110,Property,18,m,A,2019-01-01
10,57,Violence,18,m,A,2019-01-02
10,111,Property,19,m,B,2019-02-03
10,110,Property,19,m,A,2019-01-01
19,115,Property,18,m,A,2019-12-10
13,114,Property,19,m,A,2019-04-09
14,53,Violence,24,m,E,2019-06-06
15,50,Violence,21,w,A,2019-10-08
11,38,State Security,42,w,B,2019-10-01
17,10,Forgery,37,m,B,2019-02-19
99,112,Property,41,m,A,2019-02-23
98,113,Property,55,m,A,2019-07-11
;
RUN;

PROC FORMAT;
	VALUE agegrp (NOTSORTED)
	1-20 = '&amp;lt;=20'
	21-HIGH = '&amp;gt;20';
RUN;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Now, my goal is to create a crosstable as below. Unfortunately, this turned out to be very challenging. Here's my starting point:&lt;/P&gt;&lt;PRE&gt;PROC TABULATE; &lt;BR /&gt; CLASS age article title; &lt;BR /&gt; CLASS sex residenceStatus / PRELOADFMT ORDER=DATA; &lt;BR /&gt; TABLE ((title="") * (article="" ALL="Total title") ) ALL, &lt;BR /&gt;       (ALL="Total residence status" residenceStatus="") * (ALL="Total age" age="") * (ALL="Total sex" sex="") / PRINTMISS MISSTEXT="0"; &lt;BR /&gt;FORMAT age agegrp.; &lt;BR /&gt;RUN;&lt;/PRE&gt;&lt;P&gt;However this table has some major problems:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;First problem: &lt;/STRONG&gt;In the rows not all the articles should appear in every title of the criminal law: e.g. property offences are only the articles 110, 112, 113 and 115, violent crimes are only the articles 50, 53, 57 etc. (as they appear in the data)&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Second problem&lt;/STRONG&gt; (totals and subtotals):&lt;BR /&gt;- The table shows the number of suspects (persons). Therefore, the total for each title of the criminal law cannot simply be the sum of all the articles.&lt;BR /&gt;If one suspect committed several crimes within the same title (e.g. if he commited two different property crimes), he/she shall only be counted once (only the first crime within that title should be counted).&lt;BR /&gt;- The total number of crimes for the entire criminal law is not the sum of all titles, because if one suspect committed several crimes in different titles only he should only be counted as an offender of his first crime.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I cannot expect a complete solution but I'd already appreciate some explanations on how to approach it.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 15:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647840#M193917</guid>
      <dc:creator>dstuder</dc:creator>
      <dc:date>2020-05-14T15:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647847#M193919</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324367"&gt;@dstuder&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the first problem, just remove the PRINTMISS option in the TABLE statement.&lt;/P&gt;
&lt;P&gt;For the second one, you need to create a preliminary data step -&amp;gt; in the following code, I have kept only one record per personID, corresponding to the earlier date of crime. Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NB: the PRELOADFMT option in the following statement as no effect as no format has been defined: &amp;nbsp;&amp;nbsp;CLASS sex residenceStatus / ORDER=DATA PRELOADFMT ;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA suspects;
INPUT 	personId :4. 
		article:$3. 
		title:$20. 
		age:3. 
		sex :$1.
		residenceStatus :$1.
  		dateOfCrime : yymmdd10.;
FORMAT dateOfCrime yymmdd10.;
INFILE DATALINES DSD;
DATALINES;
10,110,Property,18,m,A,2019-01-01
10,57,Violence,18,m,A,2019-01-01
10,111,Property,19,m,B,2019-02-03
10,110,Property,19,m,A,2019-01-01
19,115,Property,18,m,A,2019-12-10
13,114,Property,19,m,A,2019-04-09
14,53,Violence,24,m,E,2019-06-06
15,50,Violence,21,w,A,2019-10-08
11,38,State Security,42,w,B,2019-10-01
17,10,Forgery,37,m,B,2019-02-19
99,112,Property,41,m,A,2019-02-23
98,113,Property,55,m,A,2019-07-11
;
RUN;

/**** Formats */

PROC FORMAT;
	VALUE agegrp (NOTSORTED)
	1-20 = '&amp;lt;=20'
	21-HIGH = '&amp;gt;20';
RUN;

/**** If one suspect committed several crimes
	  within the same title he/she shall only
	  be counted once + if one suspect committed
	  several crimes in different titles only
	  he should only be counted as an offender
	  of his first crime. */
	  
PROC SORT DATA=suspects out=suspect_sorted;
	BY personId dateOfCrime title;
RUN;

DATA suspect_sorted2;
	SET suspect_sorted;
	BY personId dateOfCrime title;
	IF first.personId THEN OUTPUT;
RUN;

/**** Report */

PROC TABULATE DATA=suspect_sorted2; 
	CLASS age article title; 
	CLASS sex residenceStatus / ORDER=DATA ; 
	TABLE ((title="") * (article="" ALL="Total title") ) ALL, 
       (ALL="Total residence status" residenceStatus="") * (ALL="Total age" age="") * (ALL="Total sex" sex="") / MISSTEXT="0"; 
	FORMAT age agegrp.; 
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 15:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647847#M193919</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-14T15:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647850#M193920</link>
      <description>&lt;P&gt;Just a quick question: for PersonID = 10, which 'title' would you select as 3 crimes are registered for the earliest dateofcrime? Property or Violence?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-05-14 à 17.27.01.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39449i644DACC572D9D760/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-05-14 à 17.27.01.png" alt="Capture d’écran 2020-05-14 à 17.27.01.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 15:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647850#M193920</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-14T15:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647854#M193923</link>
      <description>Sorry about that, I've fixed the dates in my original post</description>
      <pubDate>Thu, 14 May 2020 15:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647854#M193923</guid>
      <dc:creator>dstuder</dc:creator>
      <dc:date>2020-05-14T15:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647856#M193924</link>
      <description>&lt;P&gt;No worries&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;So does the provided code meet your expectations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 15:49:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647856#M193924</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-14T15:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647858#M193925</link>
      <description>&lt;P&gt;&lt;STRONG&gt;First problem:&lt;/STRONG&gt; I can't remove the printmiss-statement because I still need it for the columns (since I want all the agegroups to appear in every residence status). Is there a way to define it for specific variables instead for the whole table-statement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Second problem:&lt;/STRONG&gt; Thanks very much for your code! I think the problem is more complicated. I cannot simply remove all the (not first) offences from the dataset that were committed by the same person. If a person has commited two different property offences it should be counted twice (once at article xy and once at article yz). Whereas on the "sub-total" level (title) it should only be counted &lt;STRONG&gt;once&lt;/STRONG&gt;. And on the total level (entire criminal law) the same problem. The three levels (articles, titles and criminal law) are actually based on three different sets of data and I dont know how to put these together in one crosstable.&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 16:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647858#M193925</guid>
      <dc:creator>dstuder</dc:creator>
      <dc:date>2020-05-14T16:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647860#M193926</link>
      <description>Unfortunately all those different customized calculations means that you'll likely need to summarize your data first and then use PROC REPORT or PRINT to display it.</description>
      <pubDate>Thu, 14 May 2020 15:56:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647860#M193926</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-14T15:56:34Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647865#M193928</link>
      <description>Thanks for you answer! So you mean I have to save three different PROC TABULATES?&lt;BR /&gt;&lt;BR /&gt;PROC TABULATE OUT = articles&lt;BR /&gt;PROC TABULATE OUT = titles&lt;BR /&gt;PROC TABULATE OUT = total&lt;BR /&gt;&lt;BR /&gt;Can you please give an example on how to "put together" these three datasets afterwards using PRINT or PROC REPORT (I have never used them before) or could you recommend me a tutorial on this topic?</description>
      <pubDate>Thu, 14 May 2020 16:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647865#M193928</guid>
      <dc:creator>dstuder</dc:creator>
      <dc:date>2020-05-14T16:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647867#M193929</link>
      <description>&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;And the relevant code for this paper:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/rnd/papers/sgf2008/complex_reports.zip" target="_blank"&gt;https://support.sas.com/rnd/papers/sgf2008/complex_reports.zip&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not need to use PROC TABULATE since you'll be doing the calculations more manually. I'd probably recommend going to PROC MEANS and FREQ as their output is a little bit easier to manage to get to the reporting you will need.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The paper above explains the various approaches that can be used to create your reports and the code is included as well. It's older, so there are some simpler ways to get things today but the premise is still valid.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 16:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647867#M193929</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-14T16:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Again problems with proc tabulate (totals and sub-totals)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647917#M193940</link>
      <description>&lt;P&gt;How about providing what you expect that actual table to look like?&lt;/P&gt;
&lt;P&gt;Your example data is small enough that you should be able to count things by hand.&lt;/P&gt;
&lt;P&gt;Enter the values into manually created table in a word processor if you must. Copy and paste that (hopefully)&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 20:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Again-problems-with-proc-tabulate-totals-and-sub-totals/m-p/647917#M193940</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-14T20:37:48Z</dc:date>
    </item>
  </channel>
</rss>

