<?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: SAS Studio automated code is emailing the same report three times. Why?  Code is below.... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868611#M343138</link>
    <description>&lt;P&gt;Try this at the start of your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODS _ALL_ CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2023 14:57:09 GMT</pubDate>
    <dc:creator>ChrisHemedinger</dc:creator>
    <dc:date>2023-04-07T14:57:09Z</dc:date>
    <item>
      <title>SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868601#M343130</link>
      <description>&lt;LI-CODE lang="sas"&gt;/****************************************************************************************************************/

/* THIS CODE IS INCLUDED IN BAEP_DAILY_SHELL.SAS.
/****************************************************************************************************************/

/* This code inherits the following statements from BAEP_Daily_Shell.sas: */
/* *libname BAEPData "/sasdata/nonfinance/shared/data/30day/troop support/BAEP/Scheduled_Jobs/Data"; */
/* %let exptOutPath = %str(/sasdata/nonfinance/shared/data/30day/troop support/BAEP/Scheduled_Jobs/Export); */
/* %let outPath=%str(~/sas_pc_files_data/troop support/BAEP/Brianna Lake/Daily Runs/Output); */
/****************************************************************************************************************/
data _NULL_;
  call symputx("reportdate",put(intnx('day',today(),-1),mmddyyd10.));

  /*MUST CHANGE NUMBER OF DAYS TO SUBTRACT FOR PRIOR MONTH'S EOM */
  /*Formatted for humans.*/
run;

%let outfile=%str(XXX Report_&amp;amp;reportdate..xlsx);

/* %put &amp;amp;outfile.; */
%let currdate=%sysfunc(today()); /* No formatting applied yet. */
%let startdate=%sysfunc(intnx(month,&amp;amp;currdate,-1,B)); /* No formatting applied yet. */
%let enddate=%sysfunc(intnx(month,&amp;amp;currdate,-1,E)); /* No formatting applied yet. */

data _NULL_;
  startdate_=&amp;amp;startdate.;
  enddate_=&amp;amp;enddate.;
  call symput('startdate_edw',CATS(year(startdate_),put(month(startdate_),z2.),put(day(startdate_),z2.))); /* Formatted for EDW HANA. */
  call symput('enddate_edw',CATS(year(enddate_),put(month(enddate_),z2.),put(day(enddate_),z2.))); /* Formatted for EDW HANA. */
  call symput('startdate_hum',put(startdate_,mmddyy10.));

  /* Formatted for humans. /* Formatted for humans. */
  call symput('enddate_hum',put(enddate_,mmddyy10.));
  call symputx("reportdate",put(intnx('day',today(),-1),mmddyyd10.)); /*Formatted for humans.*/
run;

/****************************************************************************************************************/
/****************************************************************************************************************/
proc sql;
  connect to saphana as pvcon (&amp;amp;PVCONSTR.);
  create table test as select * from connection to pvcon
    (
  select distinct
    substr(o30._BIC_BORGDNUM,1,6) as DoDAAC,
    b.M_BIC_BPRCGRCD5 as PGC,
    to_date(nullif(o30._BIC_BORDER_DT,'00000000'),'YYYYMMDD') as "Order Create Date",
    o30._BIC_BBSTNK as "Customer PO Number",
    o30._BIC_BORGDNUM as "Original Doc Num",
    o30._BIC_BSUFX_CD as SFX,
    b.M_BIC_B_NIIN_DESC_SH as Nomenclature,
    b.M_BIC_B_NSN as NSN,
    sum(o30.CONF_QTY) as Quantity,
    o30._BIC_BPRI_CD as "Pri Code",
    o30.BASE_UOM as "U/I",
    o30._BIC_BSUPPADR as "Supp Address",
    b.M_EANUPC as UPC,
    o30._BIC_BDMDPLANT as RIC,
    o30._BIC_BSUPP_ST as "Status",
    coalesce(to_date(nullif(o30.CH_ON,'00000000'),'YYYYMMDD'),to_date(nullif(o30.CREATEDON,'00000000'),'YYYYMMDD')) as "Status Date",
    sum(o30.NET_VALUE) as Price
  from "_SYS_BIC"."EDW.SQL/CV_OM_BOFHO30" o30
    left join "_SYS_BIC"."EDW.SQL/CV_CS_MATERIAL" b
      on o30.MATERIAL= b.M_MATERIAL
    left join "_SYS_BIC"."EDW.SQL/CV_CS_ITEM_DETAIL" id
      on o30.MATERIAL = id.MATERIAL
    left join "_SYS_BIC"."EDW.SQL/CV_CS_PROFIT_CTR" pc
      on b.M_PROFIT_CTR = pc.PC_PROFIT_CTR
    where pc.PC_SUPPLY_CHAIN_DESC ='C&amp;amp;T'
      and o30._BIC_BSUPP_ST not in (/*'SS',*/'')
      and substr(o30._BIC_BORGDNUM,1,6) in ('Z47912')
      and o30._BIC_BEARCDTE='00000000'
      /* and o30._BIC_BSHIP_QTY='0' */
    group by substr(o30._BIC_BORGDNUM,1,6), b.M_BIC_BPRCGRCD5, o30._BIC_BORGDNUM, o30._BIC_BSUFX_CD, b.M_BIC_B_NIIN_DESC_SH,
      b.M_BIC_B_NSN, o30._BIC_BPRI_CD, o30.BASE_UOM, o30._BIC_BSUPPADR, b.M_EANUPC, o30._BIC_BDMDPLANT, o30._BIC_BSUPP_ST,
      coalesce(to_date(nullif(o30.CH_ON,'00000000'),'YYYYMMDD'),to_date(nullif(o30.CREATEDON,'00000000'),'YYYYMMDD')),
      to_date(nullif(o30._BIC_BORDER_DT,'00000000'),'YYYYMMDD'),
      o30._BIC_BBSTNK
    );
  disconnect from pvcon;
quit;

PROC EXPORT DATA=test (where=(Status not in ('B4','BQ','BR','BS','BF','C1','C2','C3','C4','C5','C6','C7','C8','CA','CB','CC','CD','CE','CF','CG','CH','CJ','CK','CL','CM','CN','CP','CQ','CR',
  'CS','CT','CU','CV','CW','CX','CY','CZ','D1','D2','D3','D4','D5','D6','D8','CA','DB','DE','DF','DJ','DN','DP','DQ','DR','DY','PC','PG','PH','PJ')))
  OUTFILE="&amp;amp;exptOutPath./&amp;amp;outfile."
  DBMS=xlsx REPLACE;
  SHEET="Open";
RUN;

PROC EXPORT DATA=test (where=(Status in ('B4','BQ','BR','BS','BF','C1','C2','C3','C4','C5','C6','C7','C8','CA','CB','CC','CD','CE','CF','CG','CH','CJ','CK','CL','CM','CN','CP','CQ','CR',
  'CS','CT','CU','CV','CW','CX','CY','CZ','D1','D2','D3','D4','D5','D6','D8','CA','DB','DE','DF','DJ','DN','DP','DQ','DR','DY','PC','PG','PH','PJ')))
  OUTFILE="&amp;amp;exptOutPath./&amp;amp;outfile."
  DBMS=xlsx REPLACE;
  SHEET="Cancelled";
RUN;

PROC EXPORT DATA=test (where=(Status in ('SS')))
  OUTFILE="&amp;amp;exptOutPath./&amp;amp;outfile."
  DBMS=xlsx REPLACE;
  SHEET="SS";
RUN;

filename mymail email
  to=(
  "NAME1 &amp;lt;EMAIL ADDRESS&amp;gt;"


  )
  CC=(
  "NAME2 &amp;lt;EMAIL ADDRESS&amp;gt;"

  )

  from=('Trp Spt RR&amp;amp;A Data Requests &amp;lt;TrpSptRR-ADataRequests@org.com&amp;gt;')
  subject="XXX Report &amp;amp;reportdate."
  attach=( "&amp;amp;exptOutPath/&amp;amp;outfile" CONTENT_TYPE="application/xlsx")
;

data _null_;
  file mymail;
  put 'Dear All,';
  put ' ';
  put "Please see the attached XXX report with data as of &amp;amp;reportdate..";
  put ' ';
  put 'If you have any questions or concerns, please feel free to contact me.';
  put 'I would be happy to assist any way that I can.';
  put ' ';
  put 'Thank you,';
  put 'XXX';
  put ' ';
  put 'This email was sent from the SAS Grid Server.';
  put "&amp;lt;&amp;amp;_SASPROGRAMFILE.&amp;gt;";
run;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 07 Apr 2023 14:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868601#M343130</guid>
      <dc:creator>sross002</dc:creator>
      <dc:date>2023-04-07T14:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868606#M343133</link>
      <description>&lt;P&gt;I don't see anything in this code to trigger three emails, but keep in mind that SAS Studio generates its own ODS destinations (HTML, PDF, RTF -- depending on options). So you might want to use ODS CLOSE on those or change your preferences.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also clear the fileref at the end of your code to ensure it's a closed destination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename email clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Apr 2023 14:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868606#M343133</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2023-04-07T14:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868609#M343136</link>
      <description>Thanks, but where would I put the ODS CLOSE in the code?&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Apr 2023 14:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868609#M343136</guid>
      <dc:creator>sross002</dc:creator>
      <dc:date>2023-04-07T14:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868611#M343138</link>
      <description>&lt;P&gt;Try this at the start of your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ODS _ALL_ CLOSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 14:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868611#M343138</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2023-04-07T14:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868616#M343141</link>
      <description>Is the below code correct for the EMAIL CLEAR function....?&lt;BR /&gt;( "&amp;amp;exptOutPath/&amp;amp;outfile" CONTENT_TYPE="application/xlsx") email clear;</description>
      <pubDate>Fri, 07 Apr 2023 15:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868616#M343141</guid>
      <dc:creator>sross002</dc:creator>
      <dc:date>2023-04-07T15:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868620#M343144</link>
      <description>&lt;P&gt;No. Just add this single line at the end of your code (after the last DATA step):&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;filename email clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 15:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868620#M343144</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2023-04-07T15:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Studio automated code is emailing the same report three times. Why?  Code is below....</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868632#M343147</link>
      <description>&lt;P&gt;thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 16:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Studio-automated-code-is-emailing-the-same-report-three/m-p/868632#M343147</guid>
      <dc:creator>sross002</dc:creator>
      <dc:date>2023-04-07T16:25:39Z</dc:date>
    </item>
  </channel>
</rss>

