您的位置:首页 > 运维架构 > Linux

SAS Email - Linux Platform

2016-02-26 13:49 896 查看
%macro auto_email;

%let file='/mnt/projects/public/offshore_office/yyliang/yinna.txt';
/*%let file ='\\Hqdellsas04\exports\APJ\yinna.txt';*/

LIBNAME smb_prod odbc dsn='HQDELLNZ06_SMB_SANDBOX' user=yyliang pwd=123 schema=dbo;
/*LIBNAME smb_prod NETEZZA DATABASE=smb_sandbox SERVER=hqdellnz06 AUTHDOMAIN="hqdellnz06" user=yyliang pwd=<span style="font-family: Arial, Helvetica, sans-serif;">123 </span>DBCONINIT='SET SERIALIZABLE = FALSE;' */

filename myfile &file.;

%if %sysfunc(fexist(myfile)) %then
%do;
%put File Exist;
%put %sysfunc(fdelete(myfile));
%put File deleted;
%end;
%else
%put File not exist.;

proc export
data=smb_prod.tmp_sas_email_2
outfile=&file.
DBMS=DLM;
delimiter='|';
run;

data temp;
infile &file. MISSOVER DSD lrecl=60000 firstobs=2 delimiter='|' encoding=utf8 ;
input
CVMID:$20.
companyname:$200.
accounttype:$200.
priority:$200.
recommend:$200.
purchase_history:$200.
email:$100.
;
label companyname="公司名称" accounttype="账户属性" priority="优先级" recommend="推荐产品" purchase_history="曾购产品";
run;

/*proc print data=temp label obs="序号"; run;*/

%if %sysfunc(fexist(myfile)) %then
%do;
%put File Exist;
%put %sysfunc(fdelete(myfile));
%put File deleted;
%end;
%else
%put File not exist.;

proc sql errorstop;
select count(distinct email) into :email_cnt
from temp
where email <>''  ;

select distinct email into :email_list  separated by ' '
from temp
where email<>''  ;
quit;

%put email_cnt is : &email_cnt.;
%put email_list: &email_list.;

%do i=1 %to &email_cnt.;
%let email_addr= %scan( &email_list. , &i., %str(' ') );

%put email_addr is : &email_addr.;

proc sql errorstop;
create table temp_email as
select CVMID, companyname, accounttype, priority, recommend, purchase_history
from temp
where email= "&email_addr";
quit;

data _null_;
set temp_email nobs=nobs;
call symputx("nobs", nobs);
stop;
run;

%put nobs= &nobs.;
%put There are &nobs. account(s) in the email &email_addr.;

Data _null_;
format GDC_time  time9.;

GDC_time=intnx("second", time(), -gmtoff());
GDC_time=intnx("min", GDC_time,  60*8);

if (GDC_time>24*3600) then
do;
put "Bigger then 24 hours";
GDC_time=intnx("min", GDC_time,  -24*60);
GDC_date=date()+1;
end;
else do;
put "Lower than 24";
GDC_date=date();
end;

call symput('GDC_date', put(GDC_date, yymmdd10.));
call symput('GDC_time', put(GDC_time, time9.));
run;

ODS HTML BODY=output STYLE=Sasweb;
TITLE JUSTIFY=left
"<head><font size=4> Dear Sir/Madam, 本周内您需要联系维护的客户信息如下: </head>

<body><br></body>
<body><font size=2> 请注意,本次邮件内容仅为测试数据,请勿做任何商业使用。谢谢合作 </body>
<body><font size=2> 如有任何问题,请联系 Tony Zhu (Tony_zhu2@Dell.com), Sophie Zhang(sszhang@merkleinc.com)。 </body>
<br>
<body><font size=2> 本次邮件发送时间: &GDC_date. &GDC_time. </body>
";

proc print data=temp_email label obs="序号";
run;

ODS HTML CLOSE;

filename output EMAIL
sender=("wzhao@merkleinc.com")
to=("&email_addr.")
subject='D&R Account 联系维护客户名单 - 测试邮件'
ct='text/html'
encoding=UTF8;

%end;

%mend;

%auto_email;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: