<?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 How do I use SAS Datastep to write output to Excel and Email content as message body in Outlook in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-use-SAS-Datastep-to-write-output-to-Excel-and-Email/m-p/530339#M5739</link>
    <description>&lt;P&gt;I am trying to ask SAS to output a small dataset(s) to Excel, copy the contents to the body of an outlook email message, send email and gracefully exit the procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a solution that produces a text output in the email body. Please see code below. I would like to improve this by 1) formatting the message body as an excel table 2) using excel to call outlook to send email. I am unsuccessful in using ODS HTML as the body of the email due to exchange security restrictions (see issue described here &lt;A href="https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-EMAIL-only-HTML-code-appears-in-the-body-no-table/td-p/178526" target="_blank"&gt;https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-EMAIL-only-HTML-code-appears-in-the-body-no-table/td-p/178526&lt;/A&gt;). Using SAS to invoke Outlook causes a security pop-up to appear that has to be manually cleared. I have tried the code snippet here (&lt;A href="https://support.microsoft.com/en-us/help/816644/how-to-send-a-range-of-cells-in-an-e-mail-message-by-using-visual-basi" target="_blank"&gt;https://support.microsoft.com/en-us/help/816644/how-to-send-a-range-of-cells-in-an-e-mail-message-by-using-visual-basi&lt;/A&gt;) and it works without invoking a pop-up. I would like to write and invoke this vba sub from SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If folks have a better solution or questions for clarification please feel free to ping me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;select count(*)&lt;BR /&gt;into :N_Crp_Fail&lt;BR /&gt;from Fails_corp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct Ult_Issuer_Name_qc, Total_Exposure&lt;BR /&gt;into :UP_Name1 - :UP_Name%left(&amp;amp;N_Crp_Fail), :Exp1 - :Exp%left(&amp;amp;N_Crp_Fail)&lt;BR /&gt;from Fails_corp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select count(*)&lt;BR /&gt;into :N_Stf_Fail&lt;BR /&gt;from Fails_structured;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct sm_sec_desc, BHF_Credit_Exposure&lt;BR /&gt;into :Sec1 - :Sec%left(&amp;amp;N_Stf_Fail), :SExp1 - :SExp%left(&amp;amp;N_Stf_Fail)&lt;BR /&gt;from Fails_structured;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro eia_agl_email;&lt;BR /&gt;DATA _NULL;&lt;BR /&gt;FILE&lt;BR /&gt;MAILBOX EMAIL TO = ('xy@abc.com')&lt;BR /&gt;SUBJECT=" &amp;amp;ENV. - Limit Fails as of &amp;amp;As_of_Date1. using 2019 limits structure"&lt;BR /&gt;CONTENT_TYPE = "text/html"&lt;BR /&gt;ATTACH = ("&amp;amp;Output_CSV_lib.Fails_corp.csv"&lt;BR /&gt;"&amp;amp;Output_CSV_lib.Fails_structured.csv"&lt;BR /&gt;);&lt;BR /&gt;if 0 then set Fails_corp nobs=nFails_Corp;&lt;BR /&gt;put "Number of corporate limit fails using 2019 limits structure: " nFails_corp;&lt;BR /&gt;put " ";&lt;BR /&gt;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;N_Crp_Fail;&lt;BR /&gt;PUT "&amp;amp;&amp;amp;UP_Name&amp;amp;i";&lt;BR /&gt;PUT "$&amp;amp;&amp;amp;Exp&amp;amp;i";&lt;BR /&gt;PUT " ";&lt;BR /&gt;%END;&lt;BR /&gt;&lt;BR /&gt;if 0 then set Fails_structured nobs=nFails_structured;&lt;BR /&gt;put "Number of structured finance limit fails using 2019 limits structure: " nFails_structured;&lt;BR /&gt;put " ";&lt;/P&gt;&lt;P&gt;%DO i = 1 %TO &amp;amp;N_Stf_Fail;&lt;BR /&gt;PUT "&amp;amp;&amp;amp;Sec&amp;amp;i";&lt;BR /&gt;PUT "$&amp;amp;&amp;amp;SExp&amp;amp;i";&lt;BR /&gt;PUT " ";&lt;BR /&gt;%END;&lt;BR /&gt;&lt;BR /&gt;put "Collateral Date available in this run: &amp;amp;Collat_Date1";&lt;BR /&gt;put " ";&lt;BR /&gt;put "XML Date available in this run: &amp;amp;xml_dt";&lt;BR /&gt;&lt;BR /&gt;stop;&lt;BR /&gt;&lt;BR /&gt;RUN;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%eia_agl_email;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notes: The above code snippet is at the very tail end of a large process. I want to send the contents (formatted as a table) of&amp;nbsp;Fails_corp and&amp;nbsp;Fails_structured (2 tables) in the body of one email to a distribution list specified in "to" field. We are using SAS 9.04 on WX64_WKS and Office 365 ProPlus Excel version 1808.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original site validation data&lt;BR /&gt;Current version: 9.04.01M5P091317&lt;BR /&gt;Site name: '--------------'.&lt;BR /&gt;Site number: xxxxxx.&lt;BR /&gt;Expiration: 30DEC2019.&lt;BR /&gt;Grace Period: 45 days (ending 13FEB2020).&lt;BR /&gt;Warning Period: 45 days (ending 29MAR2020).&lt;BR /&gt;System birthday: 05DEC2018.&lt;BR /&gt;Operating System: WX64_WKS.&lt;BR /&gt;Product expiration dates:&lt;BR /&gt;---Base SAS Software&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/STAT&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/GRAPH&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/Secure 168-bit&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/Secure Windows&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS Enterprise Guide&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ACCESS Interface to PC Files&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ACCESS Interface to ODBC&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS Workspace Server for Local Access&lt;BR /&gt;30DEC2019&lt;BR /&gt;---High Performance Suite&lt;BR /&gt;30DEC2019&lt;/P&gt;</description>
    <pubDate>Sat, 26 Jan 2019 18:03:47 GMT</pubDate>
    <dc:creator>indra1975</dc:creator>
    <dc:date>2019-01-26T18:03:47Z</dc:date>
    <item>
      <title>How do I use SAS Datastep to write output to Excel and Email content as message body in Outlook</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-use-SAS-Datastep-to-write-output-to-Excel-and-Email/m-p/530339#M5739</link>
      <description>&lt;P&gt;I am trying to ask SAS to output a small dataset(s) to Excel, copy the contents to the body of an outlook email message, send email and gracefully exit the procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a solution that produces a text output in the email body. Please see code below. I would like to improve this by 1) formatting the message body as an excel table 2) using excel to call outlook to send email. I am unsuccessful in using ODS HTML as the body of the email due to exchange security restrictions (see issue described here &lt;A href="https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-EMAIL-only-HTML-code-appears-in-the-body-no-table/td-p/178526" target="_blank"&gt;https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-EMAIL-only-HTML-code-appears-in-the-body-no-table/td-p/178526&lt;/A&gt;). Using SAS to invoke Outlook causes a security pop-up to appear that has to be manually cleared. I have tried the code snippet here (&lt;A href="https://support.microsoft.com/en-us/help/816644/how-to-send-a-range-of-cells-in-an-e-mail-message-by-using-visual-basi" target="_blank"&gt;https://support.microsoft.com/en-us/help/816644/how-to-send-a-range-of-cells-in-an-e-mail-message-by-using-visual-basi&lt;/A&gt;) and it works without invoking a pop-up. I would like to write and invoke this vba sub from SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If folks have a better solution or questions for clarification please feel free to ping me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL NOPRINT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;select count(*)&lt;BR /&gt;into :N_Crp_Fail&lt;BR /&gt;from Fails_corp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct Ult_Issuer_Name_qc, Total_Exposure&lt;BR /&gt;into :UP_Name1 - :UP_Name%left(&amp;amp;N_Crp_Fail), :Exp1 - :Exp%left(&amp;amp;N_Crp_Fail)&lt;BR /&gt;from Fails_corp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select count(*)&lt;BR /&gt;into :N_Stf_Fail&lt;BR /&gt;from Fails_structured;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select distinct sm_sec_desc, BHF_Credit_Exposure&lt;BR /&gt;into :Sec1 - :Sec%left(&amp;amp;N_Stf_Fail), :SExp1 - :SExp%left(&amp;amp;N_Stf_Fail)&lt;BR /&gt;from Fails_structured;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro eia_agl_email;&lt;BR /&gt;DATA _NULL;&lt;BR /&gt;FILE&lt;BR /&gt;MAILBOX EMAIL TO = ('xy@abc.com')&lt;BR /&gt;SUBJECT=" &amp;amp;ENV. - Limit Fails as of &amp;amp;As_of_Date1. using 2019 limits structure"&lt;BR /&gt;CONTENT_TYPE = "text/html"&lt;BR /&gt;ATTACH = ("&amp;amp;Output_CSV_lib.Fails_corp.csv"&lt;BR /&gt;"&amp;amp;Output_CSV_lib.Fails_structured.csv"&lt;BR /&gt;);&lt;BR /&gt;if 0 then set Fails_corp nobs=nFails_Corp;&lt;BR /&gt;put "Number of corporate limit fails using 2019 limits structure: " nFails_corp;&lt;BR /&gt;put " ";&lt;BR /&gt;&lt;BR /&gt;%DO i = 1 %TO &amp;amp;N_Crp_Fail;&lt;BR /&gt;PUT "&amp;amp;&amp;amp;UP_Name&amp;amp;i";&lt;BR /&gt;PUT "$&amp;amp;&amp;amp;Exp&amp;amp;i";&lt;BR /&gt;PUT " ";&lt;BR /&gt;%END;&lt;BR /&gt;&lt;BR /&gt;if 0 then set Fails_structured nobs=nFails_structured;&lt;BR /&gt;put "Number of structured finance limit fails using 2019 limits structure: " nFails_structured;&lt;BR /&gt;put " ";&lt;/P&gt;&lt;P&gt;%DO i = 1 %TO &amp;amp;N_Stf_Fail;&lt;BR /&gt;PUT "&amp;amp;&amp;amp;Sec&amp;amp;i";&lt;BR /&gt;PUT "$&amp;amp;&amp;amp;SExp&amp;amp;i";&lt;BR /&gt;PUT " ";&lt;BR /&gt;%END;&lt;BR /&gt;&lt;BR /&gt;put "Collateral Date available in this run: &amp;amp;Collat_Date1";&lt;BR /&gt;put " ";&lt;BR /&gt;put "XML Date available in this run: &amp;amp;xml_dt";&lt;BR /&gt;&lt;BR /&gt;stop;&lt;BR /&gt;&lt;BR /&gt;RUN;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%eia_agl_email;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notes: The above code snippet is at the very tail end of a large process. I want to send the contents (formatted as a table) of&amp;nbsp;Fails_corp and&amp;nbsp;Fails_structured (2 tables) in the body of one email to a distribution list specified in "to" field. We are using SAS 9.04 on WX64_WKS and Office 365 ProPlus Excel version 1808.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Original site validation data&lt;BR /&gt;Current version: 9.04.01M5P091317&lt;BR /&gt;Site name: '--------------'.&lt;BR /&gt;Site number: xxxxxx.&lt;BR /&gt;Expiration: 30DEC2019.&lt;BR /&gt;Grace Period: 45 days (ending 13FEB2020).&lt;BR /&gt;Warning Period: 45 days (ending 29MAR2020).&lt;BR /&gt;System birthday: 05DEC2018.&lt;BR /&gt;Operating System: WX64_WKS.&lt;BR /&gt;Product expiration dates:&lt;BR /&gt;---Base SAS Software&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/STAT&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/GRAPH&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ETS&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/Secure 168-bit&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/Secure Windows&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS Enterprise Guide&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ACCESS Interface to PC Files&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS/ACCESS Interface to ODBC&lt;BR /&gt;30DEC2019&lt;BR /&gt;---SAS Workspace Server for Local Access&lt;BR /&gt;30DEC2019&lt;BR /&gt;---High Performance Suite&lt;BR /&gt;30DEC2019&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jan 2019 18:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-use-SAS-Datastep-to-write-output-to-Excel-and-Email/m-p/530339#M5739</guid>
      <dc:creator>indra1975</dc:creator>
      <dc:date>2019-01-26T18:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use SAS Datastep to write output to Excel and Email content as message body in Outlook</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-use-SAS-Datastep-to-write-output-to-Excel-and-Email/m-p/530624#M5780</link>
      <description>Use proc export to create the excel file.  Then you can simply attach it like you're doing for the CSV.</description>
      <pubDate>Mon, 28 Jan 2019 13:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-use-SAS-Datastep-to-write-output-to-Excel-and-Email/m-p/530624#M5780</guid>
      <dc:creator>tomrvincent</dc:creator>
      <dc:date>2019-01-28T13:59:58Z</dc:date>
    </item>
  </channel>
</rss>

