<?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 FREQ and MEANS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611827#M178422</link>
    <description>&lt;P&gt;Complex tables like this aren't going to come directly from PROC FREQ and PROC MEANS. You probably ought to consider using PROC REPORT or PROC TABULATE, but even so, I don't think either of those can produce your tables exactly as you show them. You may need to either re-design the tables, or use the results of PROC FREQ and PROC MEANS in a Data step, where you can program the exact appearance of the tables as you want them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess this requires more discussion, how exactly do the SAS outputs have to match what you show, and how much work are you willing to put into it to get there.&lt;/P&gt;</description>
    <pubDate>Sun, 15 Dec 2019 01:31:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-12-15T01:31:51Z</dc:date>
    <item>
      <title>Proc FREQ and MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611825#M178421</link>
      <description>&lt;P&gt;Hi, I need help with creating frequency table (count and %)&amp;nbsp; by treatment groups&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;group&lt;/TD&gt;&lt;TD&gt;age&lt;/TD&gt;&lt;TD&gt;weight&lt;/TD&gt;&lt;TD&gt;gender&lt;/TD&gt;&lt;TD&gt;race&lt;/TD&gt;&lt;TD&gt;ethnicity&lt;/TD&gt;&lt;TD&gt;diabetes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;placebo&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;female&lt;/TD&gt;&lt;TD&gt;white&lt;/TD&gt;&lt;TD&gt;hispanic&lt;/TD&gt;&lt;TD&gt;yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;treatment&lt;/TD&gt;&lt;TD&gt;35&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;male&lt;/TD&gt;&lt;TD&gt;asian&lt;/TD&gt;&lt;TD&gt;not hispanic&lt;/TD&gt;&lt;TD&gt;no&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;placebo&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;153&lt;/TD&gt;&lt;TD&gt;female&lt;/TD&gt;&lt;TD&gt;unknown&lt;/TD&gt;&lt;TD&gt;hispanic&lt;/TD&gt;&lt;TD&gt;no&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;placebo&lt;/TD&gt;&lt;TD&gt;34&lt;/TD&gt;&lt;TD&gt;124&lt;/TD&gt;&lt;TD&gt;male&lt;/TD&gt;&lt;TD&gt;white&lt;/TD&gt;&lt;TD&gt;hispanic&lt;/TD&gt;&lt;TD&gt;yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;treatment&lt;/TD&gt;&lt;TD&gt;27&lt;/TD&gt;&lt;TD&gt;110&lt;/TD&gt;&lt;TD&gt;male&lt;/TD&gt;&lt;TD&gt;white&lt;/TD&gt;&lt;TD&gt;not hispanic&lt;/TD&gt;&lt;TD&gt;yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;treatment&lt;/TD&gt;&lt;TD&gt;44&lt;/TD&gt;&lt;TD&gt;135&lt;/TD&gt;&lt;TD&gt;male&lt;/TD&gt;&lt;TD&gt;asian&lt;/TD&gt;&lt;TD&gt;not hispanic&lt;/TD&gt;&lt;TD&gt;yes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;treatment&lt;/TD&gt;&lt;TD&gt;23&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;female&lt;/TD&gt;&lt;TD&gt;asian&lt;/TD&gt;&lt;TD&gt;not hispanic&lt;/TD&gt;&lt;TD&gt;no&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The denominator for placebo is 3 and treatment is 4. Something like?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;placebo_n&lt;/TD&gt;&lt;TD&gt;placebo_pct&lt;/TD&gt;&lt;TD&gt;treatment_n&lt;/TD&gt;&lt;TD&gt;treatment_pct&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;female&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;66.7%&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;25.0%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;male&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;33.3%&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;75.0%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;asian&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;75.0%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unknown&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;33.3%&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;white&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;33.3%&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;25.0%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I tried proc freq data=test; by treatment; tables gender*treatment race*treatment;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 01:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611825#M178421</guid>
      <dc:creator>monday89</dc:creator>
      <dc:date>2019-12-15T01:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FREQ and MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611827#M178422</link>
      <description>&lt;P&gt;Complex tables like this aren't going to come directly from PROC FREQ and PROC MEANS. You probably ought to consider using PROC REPORT or PROC TABULATE, but even so, I don't think either of those can produce your tables exactly as you show them. You may need to either re-design the tables, or use the results of PROC FREQ and PROC MEANS in a Data step, where you can program the exact appearance of the tables as you want them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess this requires more discussion, how exactly do the SAS outputs have to match what you show, and how much work are you willing to put into it to get there.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2019 01:31:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611827#M178422</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-12-15T01:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FREQ and MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611835#M178425</link>
      <description>&lt;P&gt;Proc tabulate can do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  picture pct low-high='000.0%';
run;

proc tabulate data=have noseps;
  class group  gender race;
  tables gender='00'x
         race='00'x
      ,  group=' '*(N='N'*f=comma6.0 colpctn='Pct'*f=pct7.0)
    /rts=10 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;The PROC FORMAT establishes a user-defined format, named PCT.&amp;nbsp; It converts the number 33.3 to 33.3%&amp;nbsp; (sort of like putting a dollar sign in front of a number for report purposes.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;The tables statement lists 2 classification variables (gender and race) prior to the comma.&amp;nbsp; These are the row identifiers.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;If I didn't have the &lt;EM&gt;&lt;STRONG&gt;='00'x&lt;/STRONG&gt;&lt;/EM&gt; then the words GENDER and RACE would appear in the left-most column, with the remainder of the row containing blank cells.&amp;nbsp; These rows would be followed by one row per value of that variable.&lt;BR /&gt;&lt;BR /&gt;I could have used &lt;EM&gt;&lt;STRONG&gt;=' '&lt;/STRONG&gt;&lt;/EM&gt;, but that would have generated a true blank in the left column.&amp;nbsp; The row would consequently be all true blank cells, which tabulate would compress out of the final table.&amp;nbsp; By using the &lt;EM&gt;&lt;STRONG&gt;='00'x&lt;/STRONG&gt;&lt;/EM&gt; &amp;nbsp; (hexadecimal 00), it will print as a blank, but not be a true blank, so a visually blank row will separate the gender rows from the race rows.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Following the comma is the column specification.&amp;nbsp; It will have two major columns (for group=placebo and treatment), and each of those will have two minor columns, one with frequencies, and one with percentages (using COLPCTN as the denominator specification).&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;The "f=" expressions determine formats.&amp;nbsp; I use a sas-standard format (comma6.0) for the N stat, and my user-defined format (pct) for the percentage.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, SAS has its own standard PERCENT format, but it converts .333 to 33.3%, and converts 333 to 3333%.&amp;nbsp; And when proc tabulate generates percents, they range from 0 to 100, not 0 to 1. &amp;nbsp;So I had to make my own format (unless someone can show me an equivalent sas-supplied format).&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>Sun, 15 Dec 2019 03:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611835#M178425</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-12-15T03:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc FREQ and MEANS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611856#M178438</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/303622"&gt;@monday89&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to create a table you can try the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input ID 1 group $ 3-11 age 13-14 weight 16-18 gender $ 20-25 race $ 27-33 ethnicity $ 35-46 diabetes $ 48-51;
	datalines;
1 placebo   25 150 female white   hispanic     yes
2 treatment 35 123 male   asian   not hispanic no
3 placebo   23 153 female unknown hispanic     no
4 placebo   34 124 male   white   hispanic     yes
5 treatment 27 110 male   white   not hispanic yes
6 treatment 44 135 male   asian   not hispanic yes
7 treatment 23 100 female asian   not hispanic no
;
run;

/* compute frequencies */
proc freq data=test;
	tables gender * group / out= group_gender (drop=percent);
	tables race * group   / out= group_race   (drop=percent);
run;

/* compute percentages */
proc sql;
	
	create table group_gender_n_pct as
	select a.gender,a.group,a.count,a.count/b.total as percent format=percent8.2
	from group_gender as a full join
		 (select group, sum(count) as total from group_gender group by group) as b
	on a.group = b.group
	order by gender;
	
	create table group_race_n_pct as
	select a.race,a.group,a.count,a.count/b.total as percent format=percent8.2
	from group_race as a full join
		 (select group, sum(count) as total from group_race group by group) as b
	on a.group = b.group
	order by race;
	
quit;

/* transpose data */

data group_gender_tr;
	length category $20.;
	merge group_gender_n_pct (where=(group="treatment") rename=(count = treatment_n percent=treatment_pct))
		  group_gender_n_pct (where=(group="placebo")   rename=(count = placebo_n percent=placebo_pct));
	by gender;
	category = gender;
	drop group gender;
run;

data group_race_tr;
	length category $20.;
	merge group_race_n_pct (where=(group="treatment") rename=(count = treatment_n percent=treatment_pct))
		  group_race_n_pct (where=(group="placebo")   rename=(count = placebo_n percent=placebo_pct));
	by race;
	category = race;
	drop group race;
run;

/* merge tables related to gender and race : table want */
data want;
	set group_gender_tr group_race_tr;
run;

proc print data=want;
	id category;
	var placebo_n placebo_pct treatment_n treatment_pct;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2019-12-15 à 10.43.38.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34779i64FF2A72270E2E12/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2019-12-15 à 10.43.38.png" alt="Capture d’écran 2019-12-15 à 10.43.38.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also create a table from PROC TABULATE as described by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  picture pct low-high='000.0%';
run;

proc tabulate data=test out=have_count noseps;
  class group  gender race;
  tables gender='00'x
         race='00'x
      ,  group=' '*(N='N'*f=comma6.0 colpctn='Pct'*f=pct7.0)
    /rts=10 ;
run;

data have_count_tr (drop= gender race _type_ _page_ _table_ PctN_100);
	format percent percent8.2;
	set have_count;
	length category $20.;
	if gender ne "" then category = gender;
	else category = race;
	percent = PctN_100 / 100;
run;

proc sort data=have_count_tr;
	by category;
run;

data want;
	merge have_count_tr  (where=(group="treatment") rename=(n = treatment_n percent = treatment_pct))
		  have_count_tr  (where=(group="placebo")   rename=(n = placebo_n percent = placebo_pct));
	by category;
	drop group;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Dec 2019 10:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-FREQ-and-MEANS/m-p/611856#M178438</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-15T10:03:24Z</dc:date>
    </item>
  </channel>
</rss>

