<?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 report: summarize across columns within another across variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/699542#M214000</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;after some attempts here is my result.&lt;/P&gt;
&lt;P&gt;I was not able to get the total over sex within year with a compute block, but I managed by creating a dummy variable in the dataset.&lt;/P&gt;
&lt;P&gt;I enclose the code so that readers can apply either the solution suggested by&amp;nbsp; PaigeMiller and ballardw or mine. (I get the word 'Total' truncated, do not know why, but it's a minor thing for me).&lt;/P&gt;
&lt;P&gt;thank you guys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;g='A'; year=1900; sex='M'; value=5; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='M'; value=2; w=15; output;&lt;BR /&gt;g='A'; year=1900; sex='F'; value=3; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='F'; value=1; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='M'; value=7; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='M'; value=4; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='F'; value=4; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='F'; value=2; w=15; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;set a;&lt;BR /&gt;dummy='T';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=have nowd;&lt;BR /&gt;columns g value,year,(sex dummy) diff,(sex dummy);&lt;BR /&gt;define g /group width=5;&lt;BR /&gt;define value /analysis sum weight=w f=8.0 '';&lt;BR /&gt;define year /across '';&lt;BR /&gt;define sex /across '';&lt;BR /&gt;define dummy /across '';&lt;BR /&gt;define diff /computed '' f=8.1 '% Change';&lt;BR /&gt;compute g ;&lt;BR /&gt;if _break_='_RBREAK_' then g='Total'; &lt;BR /&gt;endcomp;&lt;BR /&gt;rbreak after / summarize;&lt;/P&gt;
&lt;P&gt;compute diff ;&lt;BR /&gt;_c8_=100*(_c5_-_c2_)/_c2_;&lt;BR /&gt;_c9_=100*(_c6_-_c3_)/_c3_;&lt;BR /&gt;_c10_=100*(_c7_-_c4_)/_c4_;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Nov 2020 15:43:51 GMT</pubDate>
    <dc:creator>ciro</dc:creator>
    <dc:date>2020-11-17T15:43:51Z</dc:date>
    <item>
      <title>proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697684#M213259</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I am trying to produce a report that have nested across variables and within the first I need a summary column of the second variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the dataset is something like:&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;g='A'; year=1900; sex='M'; value=5; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='M'; value=2; w=15; output;&lt;BR /&gt;g='A'; year=1900; sex='F'; value=3; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='F'; value=1; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='M'; value=7; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='M'; value=4; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='F'; value=4; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='F'; value=2; w=15; output;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, I need to write an equivalent proc report code for the following proc tabulate:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc tabulate data=a;&lt;BR /&gt;class g year sex;&lt;BR /&gt;var value;&lt;BR /&gt;weight w;&lt;BR /&gt;tables g='' all='Total', year=''*(sex='' all='T')*value=''*sum=''*f=8.0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;moreover i need three more columns that represent the change between 1900 and 2000 for each sex and total&lt;/P&gt;
&lt;P&gt;I have tried with across variables and compute blocks but with no success.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 18:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697684#M213259</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2020-11-09T18:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697688#M213263</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114"&gt;@ciro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I am trying to produce a report that have nested across variables and within the first I need a summary column of the second variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the dataset is something like:&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;g='A'; year=1900; sex='M'; value=5; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='M'; value=2; w=15; output;&lt;BR /&gt;g='A'; year=1900; sex='F'; value=3; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='F'; value=1; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='M'; value=7; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='M'; value=4; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='F'; value=4; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='F'; value=2; w=15; output;&lt;BR /&gt;run;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, I need to write an equivalent proc report code for the following proc tabulate:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc tabulate data=a;&lt;BR /&gt;class g year sex;&lt;BR /&gt;var value;&lt;BR /&gt;weight w;&lt;BR /&gt;tables g='' all='Total', year=''*(sex='' all='T')*value=''*sum=''*f=8.0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;moreover i need three more columns that represent the change between 1900 and 2000 for each sex and total&lt;/P&gt;
&lt;P&gt;I have tried with across variables and compute blocks but with no success.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Really should share the proc report code attempted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Across usually means that you have to use column references, the _c1_ , _c2_ column values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will admit to being too lazy to write such report code and generally use Proc Summary and maybe a data step to generate the needed values.&lt;/P&gt;
&lt;P&gt;Plus multiple nested columns is not Proc Report's strong suit.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 18:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697688#M213263</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-09T18:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697691#M213266</link>
      <description>&lt;P&gt;So, I'm in the same rowboat as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. I'd do the arithmetic in PROC SUMMARY and then use PROC REPORT for the report itself, although I'm sure it is possible to do this entirely in PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=a;
	class sex year g;
	var value;
	weight w;
	output out=_sums_ sum=;
run;
data _sums_;
	set _sums_;
	if missing(sex) then sex='Z';
	if missing(g) then g='Z';
run;
proc format;
	value $zf 'Z'='Total';
run;
proc report data=_sums_;
	columns g year,sex,value;
	define g/group format=$zf5. ' ';
	define year/across ' ';
	define sex/across ' ' format=$zf5.;
	define value/sum ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Nov 2020 18:52:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697691#M213266</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-09T18:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697825#M213333</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you for the suggestions. I know i can do the arithmentics in proc summary and then proc report the results.&lt;/P&gt;
&lt;P&gt;however I will have to write frequently this kind of code and hope to learn to use proc report.&lt;/P&gt;
&lt;P&gt;one of my best attempts was the following:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc report data=a nowd;&lt;BR /&gt;columns g value,year,sex value,year;&lt;BR /&gt;define g /group ;&lt;BR /&gt;define value /analysis sum weight=w f=8.0;&lt;BR /&gt;define year /across '';&lt;BR /&gt;define sex /across '';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but the result is not what I want, as i need the total over sex within the year.&lt;/P&gt;
&lt;P&gt;I hope some proc report maven can help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 09:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697825#M213333</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2020-11-10T09:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697877#M213368</link>
      <description>&lt;P&gt;Certainly that's your choice to do this entirely in PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, both&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;and I think there is benefit in doing the calculations in PROC SUMMARY, perhaps you should re-consider that approach as being a valuable approach.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 12:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/697877#M213368</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-10T12:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/699542#M214000</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;after some attempts here is my result.&lt;/P&gt;
&lt;P&gt;I was not able to get the total over sex within year with a compute block, but I managed by creating a dummy variable in the dataset.&lt;/P&gt;
&lt;P&gt;I enclose the code so that readers can apply either the solution suggested by&amp;nbsp; PaigeMiller and ballardw or mine. (I get the word 'Total' truncated, do not know why, but it's a minor thing for me).&lt;/P&gt;
&lt;P&gt;thank you guys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a;&lt;BR /&gt;g='A'; year=1900; sex='M'; value=5; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='M'; value=2; w=15; output;&lt;BR /&gt;g='A'; year=1900; sex='F'; value=3; w=10; output;&lt;BR /&gt;g='A'; year=2000; sex='F'; value=1; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='M'; value=7; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='M'; value=4; w=15; output;&lt;BR /&gt;g='B'; year=1900; sex='F'; value=4; w=10; output;&lt;BR /&gt;g='B'; year=2000; sex='F'; value=2; w=15; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;set a;&lt;BR /&gt;dummy='T';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=have nowd;&lt;BR /&gt;columns g value,year,(sex dummy) diff,(sex dummy);&lt;BR /&gt;define g /group width=5;&lt;BR /&gt;define value /analysis sum weight=w f=8.0 '';&lt;BR /&gt;define year /across '';&lt;BR /&gt;define sex /across '';&lt;BR /&gt;define dummy /across '';&lt;BR /&gt;define diff /computed '' f=8.1 '% Change';&lt;BR /&gt;compute g ;&lt;BR /&gt;if _break_='_RBREAK_' then g='Total'; &lt;BR /&gt;endcomp;&lt;BR /&gt;rbreak after / summarize;&lt;/P&gt;
&lt;P&gt;compute diff ;&lt;BR /&gt;_c8_=100*(_c5_-_c2_)/_c2_;&lt;BR /&gt;_c9_=100*(_c6_-_c3_)/_c3_;&lt;BR /&gt;_c10_=100*(_c7_-_c4_)/_c4_;&lt;BR /&gt;endcomp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 15:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/699542#M214000</guid>
      <dc:creator>ciro</dc:creator>
      <dc:date>2020-11-17T15:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: proc report: summarize across columns within another across variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/699604#M214013</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If all you want to do is duplicate the PROC TABULATE output, you can do that with PROC REPORT, as shown below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1605644515996.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51772i5BF482AC38AC5E76/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1605644515996.png" alt="Cynthia_sas_0-1605644515996.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although it might be better to use PROC MEANS to summarize your data and create the weighted totals as you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 20:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-summarize-across-columns-within-another-across/m-p/699604#M214013</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-11-17T20:23:19Z</dc:date>
    </item>
  </channel>
</rss>

