<?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 tabulate out export table as in the result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951411#M371924</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465536"&gt;@thomasn528&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the same issue/need; it now seems to me an idea is to...&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;use PROC TABULATE to generate the exact VAR1 * VAR2 table I want, and then&lt;/LI&gt;
&lt;LI&gt;output that table to a dedicated Excel or CSV file, and then&lt;/LI&gt;
&lt;LI&gt;PROC IMPORT that Excel or CSV file to a SAS file.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This way if I do it once for, say, all numerators (OUT=num) and a second time for suitable denominators (OUT=denom), I can merge the two resulting files by VAR1 and have Ns, denominators, and rates per 100K all in the same record the way I need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I doubt you will be able to get Proc Import to import anything usable for most reports. VERY simple with exactly one row of header information might import. But the row headers are going to be a problem if you have more than one variable in the rows as they won't go to different variables. Most tabulate tables will tend to have column labels with multiple rows such as variable name or label and then the values of class variables before you get to the statistics. Which means the second row of information is usually treated as text so the body of the column is text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get to any sort of moderately complex tabulate report with nested rows and columns you will spend way more time trying to "fix" the result of import than reshaping a Tabulate generate out= data set.&lt;/P&gt;
&lt;P&gt;Export this to Excel or CSV (ODS Excel or ODS CSVALL) and then Import the result.&lt;/P&gt;
&lt;PRE&gt;proc tabulate data= sashelp.class;
   class sex age;
   var height weight;

   table (sex all='All sexes')*(age all='All ages'),
         (height weight) *( min max mean)
         ;
run;&lt;/PRE&gt;
&lt;P&gt;And this is not particularly complicated.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2024 23:26:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-11-20T23:26:53Z</dc:date>
    <item>
      <title>Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282877#M57558</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;running the following proc tabulate I get the attached output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc tabulate data=Check01;&lt;BR /&gt;class data_source YYYY;&lt;BR /&gt;var tot_amount;&lt;BR /&gt;table data_source, tot_amount*YYYY;&lt;BR /&gt;;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I specify:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;proc tabulate data=Check01 out=....;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;in order to get the same table as in the attachment?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks, SH&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12732i42F3CA492FF05228/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;</description>
      <pubDate>Fri, 08 Jul 2016 08:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282877#M57558</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-08T08:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282884#M57560</link>
      <description>&lt;PRE&gt;
Could you make a format ?

proc format;
value fmt
1900=' ';
run;

proc tabulate data=Check01;
class data_source YYYY;
format YYYY fmt.;
var tot_amount;
table data_source, tot_amount*YYYY;
run;





&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2016 09:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282884#M57560</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-08T09:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282931#M57571</link>
      <description>&lt;P&gt;The structure of the OUT table will not match what you see.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could consider using ODS to output your results instead, or you need to create table via proc transpose yourself. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 12:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282931#M57571</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-08T12:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282946#M57578</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;, is there then another way to export the table into excel?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 13:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282946#M57578</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-08T13:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282947#M57579</link>
      <description>&lt;P&gt;Have you tried ODS tagsets or ODS Excel?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 13:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282947#M57579</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-08T13:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282955#M57582</link>
      <description>&lt;P&gt;Never heard before, I am googling it despite that my initial wish was to have the table with the structure I want directly in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/sasdummy/2014/08/29/experimenting-with-ods-excel-to-create-spreadsheets-from-sas/" target="_blank"&gt;http://blogs.sas.com/content/sasdummy/2014/08/29/experimenting-with-ods-excel-to-create-spreadsheets-from-sas/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway you are saying that there is no direct way (using out or similar) and to do it I have to write 4 additional lines of code or?&lt;/P&gt;&lt;P&gt;In case yes, then I reshape the data as I want using the loyal proc sql introducing two new variables.&lt;/P&gt;&lt;P&gt;It a pity that a so easy task can get so complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 13:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282955#M57582</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-08T13:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282965#M57585</link>
      <description>Hi:&lt;BR /&gt;  You can send the PROC TABULATE table DIRECTLY to Excel using either ODS EXCEL or ODS TAGSETS.EXCELXP or, even, ODS HTML.&lt;BR /&gt;&lt;BR /&gt;The key is to get the structure you want with TABULATE and then use ODS to create output that Excel can open. &lt;BR /&gt;&lt;BR /&gt;Since you did not post data, it is hard to run a test program, but I'm sure I have something with SASHELP.CLASS that I can post.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Fri, 08 Jul 2016 14:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282965#M57585</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-08T14:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282969#M57588</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas﻿&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot for your suggestions, I am checking this ods excel functionality but to summarize your answer:&lt;/P&gt;&lt;P&gt;- I cannot do what I want using the out=.... because I got a table with structure different from the proc tabulate;&lt;/P&gt;&lt;P&gt;- I can use the ods excel but in this case the data I want will be directly exported (the feature looks anyway brilliant, I am exploring it);&lt;/P&gt;&lt;P&gt;- If I wanna get the dable that I want in sas, I should reshape it with the dear old proc sql.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 14:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282969#M57588</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-08T14:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282982#M57596</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; That is correct. The PROC TABULATE OUT= functionality will give you a summarized table, but the table will NOT have the same structure as the TABULATE output. However, you CAN use the Output Delivery System to create output that can be opened in a variety of destinations. Please see this sample code, that actually makes some sample data using SASHELP.PRDSALE (used because CLASS didn't have a year, but PRDSALE has a year value in it):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** make some fake data with years;
data check01(keep=data_source YYYY tot_amount);
  set sashelp.prdsale;
  if region = 'EAST' then data_source='curr month';
  else data_source='prev month';
  YYYY = year;
  if country = 'CANADA' then do;
     if region = 'EAST' then YYYY = .;
	 else if region = 'WEST' then YYYY = 1993;
  end;
  tot_amount=round(actual/1000,1);
run;
    
proc format;
  value yyfmt .=' '
        1993 = '1993'
        1994='1994';
run;
     &lt;BR /&gt;** need at least 9.4 M2 to create ODS EXCEL output file;
options missing = ' ';
ods html file='c:\temp\simple_tab_out.html';
ods tagsets.excelxp file='c:\temp\simple_tab_out_xp.xml' style=htmlblue;
ods csv file='c:\temp\simple_tab_out_cs.csv';
ods rtf file='c:\temp\simple_tab_out.rtf';
ods pdf file='c:\temp\simple_tab_out.pdf';
*ods excel file='c:\temp\simple_tab_out_xl.xlsx' style=htmlblue;
proc tabulate data=Check01;
  class data_source;
  class YYYY/missing;
  var tot_amount;
  table data_source, 
        tot_amount=' '*YYYY='Year'*{S={tagattr="Format:#####.00"}};
  keylabel sum=' ';
  format yyyy yyfmt.;
run;
ods _all_ close;
options missing=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am NOT going to clip all the output here in the screen shot. The RTF output and PDF output look almost the same and the TAGSETS.EXCELXP and ODS EXCEL output look almost the same too. As you can see, all of the output has the same structure as the TABULATE report table -- so you don't need to use an "export" you just need to use ODS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the output:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3969i7A21D7783338C629/image-size/original?v=v2&amp;amp;px=-1" alt="using_ODS_for_TABULATE.png" title="using_ODS_for_TABULATE.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 15:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/282982#M57596</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-08T15:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951407#M371923</link>
      <description>&lt;P&gt;I have the same issue/need; it now seems to me an idea is to...&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;use PROC TABULATE to generate the exact VAR1 * VAR2 table I want, and then&lt;/LI&gt;&lt;LI&gt;output that table to a dedicated Excel or CSV file, and then&lt;/LI&gt;&lt;LI&gt;PROC IMPORT that Excel or CSV file to a SAS file.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;This way if I do it once for, say, all numerators (OUT=num) and a second time for suitable denominators (OUT=denom), I can merge the two resulting files by VAR1 and have Ns, denominators, and rates per 100K all in the same record the way I need.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 23:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951407#M371923</guid>
      <dc:creator>thomasn528</dc:creator>
      <dc:date>2024-11-20T23:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951411#M371924</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/465536"&gt;@thomasn528&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the same issue/need; it now seems to me an idea is to...&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;use PROC TABULATE to generate the exact VAR1 * VAR2 table I want, and then&lt;/LI&gt;
&lt;LI&gt;output that table to a dedicated Excel or CSV file, and then&lt;/LI&gt;
&lt;LI&gt;PROC IMPORT that Excel or CSV file to a SAS file.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;This way if I do it once for, say, all numerators (OUT=num) and a second time for suitable denominators (OUT=denom), I can merge the two resulting files by VAR1 and have Ns, denominators, and rates per 100K all in the same record the way I need.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I doubt you will be able to get Proc Import to import anything usable for most reports. VERY simple with exactly one row of header information might import. But the row headers are going to be a problem if you have more than one variable in the rows as they won't go to different variables. Most tabulate tables will tend to have column labels with multiple rows such as variable name or label and then the values of class variables before you get to the statistics. Which means the second row of information is usually treated as text so the body of the column is text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you get to any sort of moderately complex tabulate report with nested rows and columns you will spend way more time trying to "fix" the result of import than reshaping a Tabulate generate out= data set.&lt;/P&gt;
&lt;P&gt;Export this to Excel or CSV (ODS Excel or ODS CSVALL) and then Import the result.&lt;/P&gt;
&lt;PRE&gt;proc tabulate data= sashelp.class;
   class sex age;
   var height weight;

   table (sex all='All sexes')*(age all='All ages'),
         (height weight) *( min max mean)
         ;
run;&lt;/PRE&gt;
&lt;P&gt;And this is not particularly complicated.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2024 23:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951411#M371924</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-11-20T23:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc tabulate out export table as in the result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951423#M371928</link>
      <description>&lt;P&gt;I see what you mean, for nested row headers -- which is what my VAR1*VAR2 implied in "PROCTABspeak".&amp;nbsp; I should have written VAR1, VAR2.&lt;BR /&gt;Here's the output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thomasn528_1-1732150291638.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102389iB0FABE30AE87D660/image-size/medium?v=v2&amp;amp;px=400" role="button" title="thomasn528_1-1732150291638.png" alt="thomasn528_1-1732150291638.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;And here's the messy dataset when the resulting ODS Excel file is imported:&amp;nbsp; data are out of register with their nested row headers.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thomasn528_3-1732150741245.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102391i9889A2814F6DE6D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="thomasn528_3-1732150741245.png" alt="thomasn528_3-1732150741245.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I was hasty in writing VAR1*VAR2, I should have written *VAR1, VAR2*n&amp;nbsp; &lt;EM&gt;(...VAR2*colpctn VAR2*rowpctn)&lt;/EM&gt; ", ie, not nested rows, but a simple single level of row, single level of column crosstab (with corresponding column and row percents if I like):&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;FONT face="courier new,courier" size="2"&gt;%if &amp;amp;colrow=CRb %then /*NNNN CCCC RRRR*/&lt;/FONT&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;FONT face="courier new,courier" size="2"&gt;TABLE &amp;amp;var1=' ' ALL='TOTAL',&lt;/FONT&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;FONT face="courier new,courier" size="2"&gt;(&amp;amp;var2=' ' ALL='Total')*n='Number'*f=comma10. (&amp;amp;var2=' ' ALL='Total')*colpctn='Percent'*f=&amp;amp;Cpctformat (&amp;amp;var2=' ' ALL='Total')*rowpctn='Row percent'*f=&amp;amp;Rpctformat)&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT face="courier new,courier" size="2"&gt;;&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I think this kind of PROC TAB output might export/import more cleanly, but I haven't tried it yet.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 01:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-tabulate-out-export-table-as-in-the-result/m-p/951423#M371928</guid>
      <dc:creator>thomasn528</dc:creator>
      <dc:date>2024-11-21T01:13:55Z</dc:date>
    </item>
  </channel>
</rss>

