您的位置:首页 > 其它

SAS学习笔记之输出到Excel

2014-09-02 20:45 274 查看
将SAS结果输出到Excel:

以下代码可以输出到某个sheet中,range指定sheet名称,后面的美元$符号不可以丢。

proc import out=mng
datafile="E:a.xlsx"
dbms=excel
replace;
range="sheetname$";
run;

以下代码可以自动输出到Excel:

options noxwait noxsync;

x '"D:\test.xlsx"'; /* 该文件为固定的报表模板,可以事先调整好单元格格式、字体颜色,事先写好其他不变的内容 */

data _null_;

x=sleep(10); /*给Excel启动时间*/

run;

/* The DDE link is established using */

/* Microsoft Excel SHEET1, rows 1 */

/* through 20 and columns 1 through 3 */

filename data

dde 'excel|sheet1!r4c2:r100c15' notab; /*notab关键字配合下面的'09'x是为了让每个字段输出到一个单元格,否则会出现窜行的情况*/

data data;

set result_01;

file data;

put name '09'x /*需要有put输出变量*/

name_second '09'x

date;

run;

filename data

dde 'excel|sheet2!r4c2:r300c18' notab; /*单元格的范围需要根据自己的情况做修改*/

data data;

set result_02;

file data;

put name '09'x

name_second '09'x

date;

run;

filename data

dde 'excel|sheet3!r4c2:r1000c20' notab;

data data;

set result_03;

file data;

put name '09'x

name_second '09'x

date;

run;

/* Microsoft defines the DDE topic */

/* SYSTEM to enable commands to be */

/* invoked within Excel. */

filename cmds dde 'excel|system';

/* These PUT statements are */

/* executing Excel macro commands */

data _null_;

file cmds;

put '[SAVE()]';

put '[QUIT()]';

run;

内容参考人大经济论坛、SAS帮助。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: