<?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: Print to excel from data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678561#M204818</link>
    <description>&lt;P&gt;Hi @3 and @40 are pointer controls that are only respected by the LISTING destination when you use FILE PRINT. They would NOT work with ODS EXCEL or with the XLSX libname engine. So I'm not entirely sure what you mean when you say you want to "keep the formatting as created from this code".&lt;BR /&gt;Can you show what you expect your output to look like? Without data nobody can test your code and the challenge that I see is that you have &amp;amp;dataout as both the output data and the SET data, so that is troublesome to me because using the same file on both DATA statement and SET statement can lead to problems. Probably NOT a great issue since you are doing FILE PRINT, but right now, FILE PRINT as you show will only work for LISTING. &lt;BR /&gt;For example. this is what I get when I "unmacro" your code and use 2 obs from SASHELP.SHOES (I added region to the PUT statement):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1598038215021.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48542iF13BB782C1921696/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1598038215021.png" alt="Cynthia_sas_0-1598038215021.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the DATA step to create the new structure (LONG) and then just use ODS EXCEL to create the output file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1598038871074.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48544iEBE32011B537D467/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1598038871074.png" alt="Cynthia_sas_1-1598038871074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without worrying about pointer control and DATA step to FILE PRINT - -which would not work with ODS EXCEL or the LIBNAME engine anyway.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;How do you envision this would look in Excel? If you want it in Excel, why not make a CSV file and then just open the CSV file in Excel???&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Fri, 21 Aug 2020 19:41:50 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2020-08-21T19:41:50Z</dc:date>
    <item>
      <title>Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678549#M204811</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running the following code within a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;title "&amp;amp;datain.";&lt;BR /&gt;footnote "&amp;amp;datain.";&lt;BR /&gt;data &amp;amp;dataout.;&lt;BR /&gt;set &amp;amp;dataout.;&lt;BR /&gt;file print;&lt;BR /&gt;array var {*} _numeric_;&lt;BR /&gt;do i=1 to dim(var);&lt;BR /&gt;name = vname(var(i));&lt;BR /&gt;value = var(i);&lt;BR /&gt;put @3 name @40 value /;&lt;BR /&gt;end;&lt;BR /&gt;drop i name;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the "file print" portion of this code is it possible to print to an excel file? My goal is to print this to excel and keep the formatting is created from this code. Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 18:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678549#M204811</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-08-21T18:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678561#M204818</link>
      <description>&lt;P&gt;Hi @3 and @40 are pointer controls that are only respected by the LISTING destination when you use FILE PRINT. They would NOT work with ODS EXCEL or with the XLSX libname engine. So I'm not entirely sure what you mean when you say you want to "keep the formatting as created from this code".&lt;BR /&gt;Can you show what you expect your output to look like? Without data nobody can test your code and the challenge that I see is that you have &amp;amp;dataout as both the output data and the SET data, so that is troublesome to me because using the same file on both DATA statement and SET statement can lead to problems. Probably NOT a great issue since you are doing FILE PRINT, but right now, FILE PRINT as you show will only work for LISTING. &lt;BR /&gt;For example. this is what I get when I "unmacro" your code and use 2 obs from SASHELP.SHOES (I added region to the PUT statement):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1598038215021.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48542iF13BB782C1921696/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1598038215021.png" alt="Cynthia_sas_0-1598038215021.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the DATA step to create the new structure (LONG) and then just use ODS EXCEL to create the output file:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_1-1598038871074.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48544iEBE32011B537D467/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_1-1598038871074.png" alt="Cynthia_sas_1-1598038871074.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without worrying about pointer control and DATA step to FILE PRINT - -which would not work with ODS EXCEL or the LIBNAME engine anyway.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;How do you envision this would look in Excel? If you want it in Excel, why not make a CSV file and then just open the CSV file in Excel???&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 19:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678561#M204818</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-08-21T19:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678576#M204823</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/48546i9584FEFD22714624/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;My Data looks like above when I run it through the macro. I am using&amp;nbsp;&lt;SPAN&gt;&amp;amp;dataout because I am running 30+ data sets through this code; each by month and year. Ideally, in excel or csv my data would look like above, with each month and year combination on top, the data in the respective column and the variables along the side as shown.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;An example of my data is:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data want;&lt;BR /&gt;input Complete_n partial_n com_par_percent no_res_percent Death_n Revised_n Conversion_n &lt;BR /&gt;declined_n tot_pat_for_comp clin_visit_percent xray_percent faam_percent ffi_percent &lt;BR /&gt;vr12_percent pt_percent md_percent vas_percent survey_percent;&lt;BR /&gt;cards;&lt;BR /&gt;59 200 50.6 49.4 10 23 10 0 512 36.9 40 32.5 64.5 64.5 63.5 43 70 53.5&lt;BR /&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 20:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678576#M204823</guid>
      <dc:creator>GS2</dc:creator>
      <dc:date>2020-08-21T20:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678597#M204831</link>
      <description>Hi:&lt;BR /&gt;Unless you use DDE (which is very very old Excel technology) with the DATA step, you will not be able to write directly to Excel as you envision. Writing a CSV file or using ODS EXCEL as I show in my second example is what you'll have to do. &lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 21 Aug 2020 21:49:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678597#M204831</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-08-21T21:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678600#M204832</link>
      <description>&lt;P&gt;Reshape your data so you have a variable holding your current variable name and another variable with the value. Then you could use FILE PRINT ODS to print to two "columns" in Excel.&lt;/P&gt;
&lt;P&gt;or use another procedure&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=want;
   var  Complete_n partial_n com_par_percent no_res_percent Death_n Revised_n Conversion_n
declined_n tot_pat_for_comp clin_visit_percent xray_percent faam_percent ffi_percent
vr12_percent pt_percent md_percent vas_percent survey_percent;

  table Complete_n partial_n com_par_percent no_res_percent Death_n Revised_n Conversion_n
declined_n tot_pat_for_comp clin_visit_percent xray_percent faam_percent ffi_percent
vr12_percent pt_percent md_percent vas_percent survey_percent ,
       max='Value'*f=best6.
       / box='Variable'
   ;
run;
        &lt;/PRE&gt;
&lt;P&gt;If you have other variables like Year and Month you would modify that example to:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=want;
   By Year Month;
   var  Complete_n partial_n com_par_percent no_res_percent Death_n Revised_n Conversion_n
declined_n tot_pat_for_comp clin_visit_percent xray_percent faam_percent ffi_percent
vr12_percent pt_percent md_percent vas_percent survey_percent;

  table Complete_n partial_n com_par_percent no_res_percent Death_n Revised_n Conversion_n
declined_n tot_pat_for_comp clin_visit_percent xray_percent faam_percent ffi_percent
vr12_percent pt_percent md_percent vas_percent survey_percent ,
       max='Value'*f=best6.
       / box='Variable'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;With the ODS EXCEL BODY= option to set the base file NEWFILE=BYGROUP you would get a separate file for each BY group , i.e. year and month.&lt;/P&gt;
&lt;P&gt;The only macro bit needed would be the input data set and the base file name to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 16:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678600#M204832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-24T16:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678604#M204833</link>
      <description>He already has most of the program structure in place to reshape the data using his Array. I included an example of modifying his program in my posting and highlighted the few statements that would have to change in order to create a data set with 2 columns (and I added a few more columns just for ordering purposes -- but those could be left off). &lt;BR /&gt;&lt;BR /&gt;Proc TABULATE is good and could go directly to ODS EXCEL, however using BY group processing would cause ODS EXCEL to make a new sheet for every unique year/month combination, which may or may not be what he wants.&lt;BR /&gt;Cynthia</description>
      <pubDate>Fri, 21 Aug 2020 22:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678604#M204833</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-08-21T22:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: Print to excel from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678606#M204834</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13549"&gt;@Cynthia_sas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;He already has most of the program structure in place to reshape the data using his Array. I included an example of modifying his program in my posting and highlighted the few statements that would have to change in order to create a data set with 2 columns (and I added a few more columns just for ordering purposes -- but those could be left off). &lt;BR /&gt;&lt;BR /&gt;Proc TABULATE is good and could go directly to ODS EXCEL, however using BY group processing would cause ODS EXCEL to make a new sheet for every unique year/month combination, which may or may not be what he wants.&lt;BR /&gt;Cynthia&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yep, not very clear on the actual desired output.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Aug 2020 23:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Print-to-excel-from-data-step/m-p/678606#M204834</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-21T23:08:28Z</dc:date>
    </item>
  </channel>
</rss>

