SAS 的导入、导出 excel 表格的实现
首先 SAS 可以使用手动来导入,导出
但是这样对于每次操作都需要来手动操作,所以就使用了 SAS 中的宏来编写代码
需求:
1. 首先是给定excel 的文件路径,来生成一个数据集
2. 然后是对数据集中进行数据的处理
3. 最后是对处理好的数据集导出为一个excel 格式的文件
例子:
/* 导入excel的数据 */
%macro import_excel(filepath, out);
proc import datafile=&filepath out=&out dbms=excel replace;
run;
%mend import-excel;
/* 导出excel的数据 */
%macro export_excel(dataset, filepath);
proc export data=&dataset file=&filepath dbms=excel replace;
run;
%mend export_excel();
/* 调用导入宏 */
%import_excel('C:\Users\ZEK\Desktop\test.xlsx', a);
run;
/* 处理数据集 */
data process;
set a;
if age>14 then desc='已满14岁';
else desc='未满14岁';
run;
/* 调用导出宏 */
%export_excel(process, 'C:\Users\ZEK\Desktop\temp.xlsx');
run;
结果:
在日志窗口中会输出这样的一个日志.
注意:
在编写代码的时候,最需要注意的是,导入和导出的语句是不一样的
导入为:
proc import datafile=路径名称 out=数据集名称 dbms=excel replace;
导出为:
proc export data=数据集名称 file=路径名称 dbms=excel replace;
页:
[1]