<?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: rounding counts in proc tabulate, and ods excel updating sheet name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447145#M112261</link>
    <description>&lt;P&gt;Thanks for the solution to update excel sheet name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to round to the nearest 5. e.g. 2 &amp;gt; 0, 3 &amp;gt; 5; 7 &amp;gt; 5; 8 &amp;gt; 10 ..... My actual data will have much larger numbers. The variables are categorical vars.&amp;nbsp;If you think other procedures may be easier to use, can you give me some hints?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
    <pubDate>Tue, 20 Mar 2018 14:56:20 GMT</pubDate>
    <dc:creator>sasecn</dc:creator>
    <dc:date>2018-03-20T14:56:20Z</dc:date>
    <item>
      <title>rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447092#M112249</link>
      <description>&lt;P&gt;I am using the following data sets for testing:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro getdata;
%do yr=2000 %to 2004;
data cars&amp;amp;yr.;
  set sashelp.cars (keep=type origin);
  type&amp;amp;yr.=type;
  origin&amp;amp;yr.=origin;
run;
%end;
%mend getdata;
%getdata;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My goal is to use proc tabulate to get cross-tab for each year by using:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file="H:\test.xlsx";
%macro tables;
%do yr=2000 %to 2004;
proc tabulate data=cars&amp;amp;yr.;
class type&amp;amp;yr. origin&amp;amp;yr.;
table type&amp;amp;yr.='', origin&amp;amp;yr.=''*(n='n') (all='row totals')/misstext='0';
run;
%end;
%mend tables;
%tables;
ods excel close;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;My questions are:&lt;/P&gt;&lt;P&gt;1. how to round all counts based on 5?&lt;/P&gt;&lt;P&gt;2. how to change the sheet name inside the loop? I tried to put ods statements inside the loop, but it will overwrite the sheets and only produce the last one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 13:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447092#M112249</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-03-20T13:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447133#M112256</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am using the following data sets for testing:&lt;/P&gt;
&lt;P&gt;My goal is to use proc tabulate to get cross-tab for each year by using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;My questions are:&lt;/P&gt;
&lt;P&gt;1. how to round all counts based on 5?&lt;/P&gt;
&lt;P&gt;2. how to change the sheet name inside the loop? I tried to put ods statements inside the loop, but it will overwrite the sheets and only produce the last one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for any help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may need to consider in some detail exactly how you would round something to 5. Suppose you have two categories each with an actual n of 3. Do want to round that to 0 or 5? And if you have an "All" then since the actual total n would be 6 do you want to display 5 or 10? Plus almost any other statistic other than n may look odd if shown with that rounded n.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the only thing you are doing is displaying n values you might consider using one of the other summary procedures such as Proc Means or summary to get the counts and then round in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your sheet names you would need to provide an ods excel options (sheet_name="something")&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; yr&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2000&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2004&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;ods excel options (sheet_name="&amp;amp;yr");&lt;/P&gt;
&lt;P&gt;Depending on what your actual output is you may also need to set the sheet_interval option if your output consists of more than one table that you want on a sheet. The default is sheet_interval='TABLE' which attempts to place each table onto a separate sheet. Also you might want to look at the sheet_label option as well.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447133#M112256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-20T14:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447145#M112261</link>
      <description>&lt;P&gt;Thanks for the solution to update excel sheet name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to round to the nearest 5. e.g. 2 &amp;gt; 0, 3 &amp;gt; 5; 7 &amp;gt; 5; 8 &amp;gt; 10 ..... My actual data will have much larger numbers. The variables are categorical vars.&amp;nbsp;If you think other procedures may be easier to use, can you give me some hints?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 14:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447145#M112261</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-03-20T14:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447158#M112265</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the solution to update excel sheet name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to round to the nearest 5. e.g. 2 &amp;gt; 0, 3 &amp;gt; 5; 7 &amp;gt; 5; 8 &amp;gt; 10 ..... My actual data will have much larger numbers. The variables are categorical vars.&amp;nbsp;If you think other procedures may be easier to use, can you give me some hints?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The issue is with creating inconsistent data using a proc. Here is another example to contemplate. You have 3 categorical variables each with a count of 2. So they would display 0 for each. But the total would be 6 and display as 5. So you have 0+0+0=5 in the body of your table. The larger the number of categories the higher potential displayed error in the sum could be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could build a custom format that calls a custom function built with Proc FCMP that would do the rounding and tell the n statistic to use that format with: n=' '*f=custround. for example. But you are very likely to generate data inconsistencies in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would be much better off to summarize and round the basic counts to the multiple of 5 prior to a display with&amp;nbsp;proc tabulate. Then your "all rows" total would at least match internally.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447158#M112265</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-20T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447210#M112284</link>
      <description>&lt;P&gt;Thanks for the thoughts. I am not familiar with proc fcmp. I will have a look and give it a try.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 17:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447210#M112284</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-03-20T17:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447242#M112294</link>
      <description>&lt;P&gt;Here's an example summarizing, rounding then using tabulate to display the result. Note that a var count is added that you sum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc  summary data=sashelp.cars nway;
   class type origin;
   var cylinders;
   output out=carsum (drop=_type_ _freq_) n=count;
run;

data temp;
   set carsum;
   count= round(count,5);
run;

proc tabulate data=temp;
   class type origin;
   var count;
   table type,
        ( origin all='Row total')*count*sum=''*f=best6. 
        /misstext='0';
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 19:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447242#M112294</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-20T19:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: rounding counts in proc tabulate, and ods excel updating sheet name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447261#M112301</link>
      <description>&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 20:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/rounding-counts-in-proc-tabulate-and-ods-excel-updating-sheet/m-p/447261#M112301</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-03-20T20:21:07Z</dc:date>
    </item>
  </channel>
</rss>

