<?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: creating summary table in SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610669#M18136</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302184"&gt;@sasprogramming&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to do this is to use PROC REPORT.&lt;/P&gt;
&lt;P&gt;The final report will be closer to what you expect.&lt;/P&gt;
&lt;P&gt;However, the "structure" is less flexible -&amp;gt; in the following code, only 3 modalities for the variable POINTS are taken into account (100, 200, 300) as the code refers directly to the column number in the report. Should you have more modalities, you will need to adjust the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2019-12-10 à 12.39.59.png" style="width: 372px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34578i79782CCDE7E33546/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2019-12-10 à 12.39.59.png" alt="Capture d’écran 2019-12-10 à 12.39.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x;
input ID	Month $	Points;
cards;
1	Jan	100
2	Jan	100
3	Jan	200
4	Feb	100
5	Feb	200
6	Feb	300
7	Mar	100
8	Mar	200
9	Apr	300
10	Apr	100
11	Apr	200
12	Apr	300
;
run;

data want;
set have;
select (month);
   when ('Jan') monthn=1;
   when ('Feb') monthn=2;
   when ('Mar') monthn=3;
   when ('Apr') monthn=4;
   when ('May') monthn=5;
   when ('Jun') monthn=6;
   when ('Jul') monthn=7;
   when ('Aug') monthn=8;
   when ('Sep') monthn=9;
   when ('Oct') monthn=10;
   when ('Nov') monthn=11;
   when ('Dec') monthn=12;
   otherwise;
end;
run;

proc report data=want;

	column monthn month dum_month points, (n pct dum_pct) total;
	
	define monthn / group id order=data noprint;
	define month / group noprint;
	define dum_month / computed "Month";
	define points / across;
	define n / "n" noprint ;
	define pct / computed "%" f=percent8.0 noprint;
	define dum_pct / "%" computed;
	define total / computed 'Total';
	
	/* Sum totals in row for further calculation */
	compute before month;
 	    _total = sum(_c4_, _c7_, _c10_);
    endcomp;
    
    /* Compute percentages from frequencies (n) and totals in row (_total) */
    compute pct;
		if _c4_ &amp;gt; 0 then _c5_ = _c4_ / _total;
		else _c5_ = 0;
		if _c7_ &amp;gt; 0 then _c8_ = _c7_ / _total;
		else _c8_ = 0;
		if _c10_&amp;gt; 0 then _c11_ = _c10_ / _total;
		else _c11_= 0; 
	endcomp;

	/* Sum totals in row */
	compute total;
	     total = sum(_c4_, _c7_, _c10_);
	endcomp;
 
 	/* Display either month or "Total" according to the type of row (last row or not)*/
	compute dum_month / character length=5;
		if _BREAK_="_RBREAK_" then dum_month = 'Total';
		else dum_month = month;
	endcomp;
	
	/* Display either pct or freq according to the type of row (last row or not)*/
	compute dum_pct / char;
		if _BREAK_="_RBREAK_" then do;
			_c6_ = put(_c4_,best8.);
			_c9_ = put(_c7_,best8.);
			_c12_ = put(_c10_,best8.);
			end;
		else do;
			_c6_ = put(_c5_,percent8.0);
			_c9_ = put(_c8_,percent8.0);
			_c12_ = put(_c11_,percent8.0);
			end;
		
	endcomp;
	
	rbreak after / summarize ;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Dec 2019 11:51:01 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2019-12-10T11:51:01Z</dc:date>
    <item>
      <title>creating summary table in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610613#M18129</link>
      <description>&lt;P&gt;I have the following dataset which looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;Points&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Jan&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Jan&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Jan&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Feb&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Feb&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;Feb&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;Mar&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;Mar&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;Apr&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;Apr&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;Apr&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;Apr&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way in SAS to produce a summary table that looks like this?&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Jan&lt;/TD&gt;&lt;TD&gt;67%&lt;/TD&gt;&lt;TD&gt;33%&lt;/TD&gt;&lt;TD&gt;0%&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Feb&lt;/TD&gt;&lt;TD&gt;33%&lt;/TD&gt;&lt;TD&gt;33%&lt;/TD&gt;&lt;TD&gt;33%&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Mar&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;TD&gt;0%&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Apr&lt;/TD&gt;&lt;TD&gt;25%&lt;/TD&gt;&lt;TD&gt;25%&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 05:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610613#M18129</guid>
      <dc:creator>sasprogramming</dc:creator>
      <dc:date>2019-12-10T05:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: creating summary table in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610638#M18133</link>
      <description>&lt;P&gt;Proc Tabulate will help you to summary the % values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc tabulate data = have;
class month points;
table month all, points*(n*f=8. colpctn='%') all='Total'*(n*f=8.)/rts=10;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 09:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610638#M18133</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-12-10T09:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: creating summary table in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610650#M18135</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302184"&gt;@sasprogramming&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An easy way to do that is to use a proc freq.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have2;
	table month*points / nocol nopercent nofreq ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to display months in a logical order, you can add a format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value monthn
		1 = 'Jan'
		2 = 'Feb'
		3 = 'Mar'
		4 = 'Apr'
		5 = 'May'
		6 = 'Jun'
		7 = 'Jul'
		8 = 'Aug'
		9 = 'Sep'
		10 = 'Oct'
		11 = 'Nov'
		12 = 'Dec';
run;
	
data have2;
set have;
attrib monthn format=monthn.;
select (month);
   when ('Jan') monthn=1;
   when ('Feb') monthn=2;
   when ('Mar') monthn=3;
   when ('Apr') monthn=4;
   when ('May') monthn=5;
   when ('Jun') monthn=6;
   when ('Jul') monthn=7;
   when ('Aug') monthn=8;
   when ('Sep') monthn=9;
   when ('Oct') monthn=10;
   when ('Nov') monthn=11;
   when ('Dec') monthn=12;
   otherwise;
end;
drop month;
rename monthn = Month;
run;

proc freq data=have2;
	table month*points / nocol nopercent nofreq ;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610650#M18135</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-10T11:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: creating summary table in SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610669#M18136</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302184"&gt;@sasprogramming&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to do this is to use PROC REPORT.&lt;/P&gt;
&lt;P&gt;The final report will be closer to what you expect.&lt;/P&gt;
&lt;P&gt;However, the "structure" is less flexible -&amp;gt; in the following code, only 3 modalities for the variable POINTS are taken into account (100, 200, 300) as the code refers directly to the column number in the report. Should you have more modalities, you will need to adjust the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2019-12-10 à 12.39.59.png" style="width: 372px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34578i79782CCDE7E33546/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2019-12-10 à 12.39.59.png" alt="Capture d’écran 2019-12-10 à 12.39.59.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dlm="09"x;
input ID	Month $	Points;
cards;
1	Jan	100
2	Jan	100
3	Jan	200
4	Feb	100
5	Feb	200
6	Feb	300
7	Mar	100
8	Mar	200
9	Apr	300
10	Apr	100
11	Apr	200
12	Apr	300
;
run;

data want;
set have;
select (month);
   when ('Jan') monthn=1;
   when ('Feb') monthn=2;
   when ('Mar') monthn=3;
   when ('Apr') monthn=4;
   when ('May') monthn=5;
   when ('Jun') monthn=6;
   when ('Jul') monthn=7;
   when ('Aug') monthn=8;
   when ('Sep') monthn=9;
   when ('Oct') monthn=10;
   when ('Nov') monthn=11;
   when ('Dec') monthn=12;
   otherwise;
end;
run;

proc report data=want;

	column monthn month dum_month points, (n pct dum_pct) total;
	
	define monthn / group id order=data noprint;
	define month / group noprint;
	define dum_month / computed "Month";
	define points / across;
	define n / "n" noprint ;
	define pct / computed "%" f=percent8.0 noprint;
	define dum_pct / "%" computed;
	define total / computed 'Total';
	
	/* Sum totals in row for further calculation */
	compute before month;
 	    _total = sum(_c4_, _c7_, _c10_);
    endcomp;
    
    /* Compute percentages from frequencies (n) and totals in row (_total) */
    compute pct;
		if _c4_ &amp;gt; 0 then _c5_ = _c4_ / _total;
		else _c5_ = 0;
		if _c7_ &amp;gt; 0 then _c8_ = _c7_ / _total;
		else _c8_ = 0;
		if _c10_&amp;gt; 0 then _c11_ = _c10_ / _total;
		else _c11_= 0; 
	endcomp;

	/* Sum totals in row */
	compute total;
	     total = sum(_c4_, _c7_, _c10_);
	endcomp;
 
 	/* Display either month or "Total" according to the type of row (last row or not)*/
	compute dum_month / character length=5;
		if _BREAK_="_RBREAK_" then dum_month = 'Total';
		else dum_month = month;
	endcomp;
	
	/* Display either pct or freq according to the type of row (last row or not)*/
	compute dum_pct / char;
		if _BREAK_="_RBREAK_" then do;
			_c6_ = put(_c4_,best8.);
			_c9_ = put(_c7_,best8.);
			_c12_ = put(_c10_,best8.);
			end;
		else do;
			_c6_ = put(_c5_,percent8.0);
			_c9_ = put(_c8_,percent8.0);
			_c12_ = put(_c11_,percent8.0);
			end;
		
	endcomp;
	
	rbreak after / summarize ;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2019 11:51:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/creating-summary-table-in-SAS/m-p/610669#M18136</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-10T11:51:01Z</dc:date>
    </item>
  </channel>
</rss>

