<?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: Different statistics for each variable in Proc Tabulate  (SAS 9.4) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921207#M362772</link>
    <description>&lt;P&gt;If you can provide some example data, or recast your example to use a SAS supplied data set like SASHELP.CLASS we can discuss details better.&lt;/P&gt;
&lt;P&gt;Preferably a set small enough you can show expected results calculated by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first feeling without your data is that you are likely asking Tabulate to "cross statistics", this request a row with one statistic that will intersect with a calculated statistic in a column. That will generally not work. The likely problems I see are the "Days in Clinic" "Average Days per Stay" and the Min/Max/Average age crossing with the N and ColPctN . Your Tabulate code doesn't show anything related to Cost in Column position so I suspect more details are missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of an &lt;STRONG&gt;invalid &lt;/STRONG&gt;combination of statistics that requests a row N and intersects with a column mean. You can run this and see the error message.&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=sashelp.class;
   class sex age;
   var height;
   table sex*n,
         age* height*mean
   ;
run;&lt;/PRE&gt;
&lt;P&gt;With some example data it may be possible to preprocess the data to create a table like you envision but I suspect it will take a bit of work.&lt;/P&gt;
&lt;P&gt;You can have different statistics in a column as long as the column only consists of CLASS variables. Or multiple stats in column as long as the Rows are all class variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Mar 2024 23:14:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-03-20T23:14:03Z</dc:date>
    <item>
      <title>Different statistics for each variable in Proc Tabulate  (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921204#M362770</link>
      <description>&lt;P&gt;I don't know if this is possible, but I would like different statistics for each variable in my proc tabulate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like the following for each variable:&lt;/P&gt;&lt;P&gt;Gender- N for each level and colpctn&amp;nbsp;&lt;/P&gt;&lt;P&gt;Age -min, max and median&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stays (Flag var)- sum&amp;nbsp;&lt;/P&gt;&lt;P&gt;Days- sum (and average per ID for each Clinic Name if possible)&lt;/P&gt;&lt;P&gt;Cost-sum (and average per ID for each Clinic Name if possible)&lt;/P&gt;&lt;P&gt;ID- N and colpctn ( I do not want the IDs listed down the side of the table which is what the current code is doing now. see code below)&lt;/P&gt;&lt;P&gt;All of these for each clinic name with clinic name across the top which seems to be the only thing I have achieved so far in my code below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought the proc tabulate would be the best option for this table as these statistics are not already calculated in the data, but I am open to suggestions!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Proc tabulate data=Have;
format Cost dollar32.;
where Clinic_Type='1' and Flag=1 and Cost&amp;gt;1 and SFY_Yr='2023';
class Clinic_Name Gender Age Days Flag Cost ID;
table Gender Age Days Flag Cost ID all,
Clinic_Name*(n colpctn ) all / misstext=' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Flag=1 flags a stay in clinic type 1 for clients, we are only looking at clinic type 1 (see where statement).&lt;/P&gt;&lt;P&gt;I'm looking to make something similar to this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 994px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94816i61ABD6B7974DC8CE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 22:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921204#M362770</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2024-03-20T22:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Different statistics for each variable in Proc Tabulate  (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921207#M362772</link>
      <description>&lt;P&gt;If you can provide some example data, or recast your example to use a SAS supplied data set like SASHELP.CLASS we can discuss details better.&lt;/P&gt;
&lt;P&gt;Preferably a set small enough you can show expected results calculated by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My first feeling without your data is that you are likely asking Tabulate to "cross statistics", this request a row with one statistic that will intersect with a calculated statistic in a column. That will generally not work. The likely problems I see are the "Days in Clinic" "Average Days per Stay" and the Min/Max/Average age crossing with the N and ColPctN . Your Tabulate code doesn't show anything related to Cost in Column position so I suspect more details are missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example of an &lt;STRONG&gt;invalid &lt;/STRONG&gt;combination of statistics that requests a row N and intersects with a column mean. You can run this and see the error message.&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=sashelp.class;
   class sex age;
   var height;
   table sex*n,
         age* height*mean
   ;
run;&lt;/PRE&gt;
&lt;P&gt;With some example data it may be possible to preprocess the data to create a table like you envision but I suspect it will take a bit of work.&lt;/P&gt;
&lt;P&gt;You can have different statistics in a column as long as the column only consists of CLASS variables. Or multiple stats in column as long as the Rows are all class variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2024 23:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921207#M362772</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-20T23:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Different statistics for each variable in Proc Tabulate  (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921224#M362781</link>
      <description>&lt;P&gt;I think you are correct about the invalid combination of statistics. When I attempted to add the other statistics into the proc tabulate, I received the same error as the sample you provided.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the sample data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;Data Have;
input 


Clinic_Name$ Gender$	Age	days	flag	Cost ID$	Clinic_Type	SFY_Yr$;
datalines;
A	F	16	157		1	2746 	A	1	2023
A	F	17	134		1	1373 	A	1	2023
B	M	17	169		1	5479 	B	1	2023
A	F	18	262		1	687 	C	1	2023
C	F	17	191		1	5479 	D	1	2023
D	F	17	20		1	8675 	E	1	2023
E	F	17	133		1	4566 	F	1	2023
E	F	17	60		1	10044 	F	1	2023
E	F	17	88		1	9588 	F	1	2023
A	F	17	271		1	2060 	G	1	2023
D	M	17	153		1	5022 	H	1	2023
D	M	16	118		1	913 	I	1	2023
F	M	16	328		1	457 	J	1	2023
G	F	17	179		1	10957 	K	1	2023
G	M	17	256		1	1826 	L	1	2023
H	F	17	163		1	10501 	M	1	2023
H	F	17	10		1	5022 	M	1	2023
B	M	17	105		1	7305 	N	1	2023
I	F	17	322		1	10501 	O	1	2023
A	F	17	314		1	1373 	P	1	2023

;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you for looking into this!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 02:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921224#M362781</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2024-03-21T02:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Different statistics for each variable in Proc Tabulate  (SAS 9.4)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921225#M362782</link>
      <description>&lt;P&gt;Please show what report you want from that input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a very nice utility macro out there for generating a report like you showed the row headers for in your original report.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not just use that instead of trying do it in one PROOC TABULATE call?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 02:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-statistics-for-each-variable-in-Proc-Tabulate-SAS-9-4/m-p/921225#M362782</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-21T02:42:14Z</dc:date>
    </item>
  </channel>
</rss>

