1

Another question. I have multiple data sets that generate ouput how can output these into one excel work sheet and apply my own formating. For example I have data set 1, data set 2, data set 3

each data set has two coloumns, for example
Col 1 Col 2
1    2 
3    4 
5    6

I want each data set to be in one worksheet and seperated by column , so in excel it should look like

Col 1 Col 2 Blank Col Col 1 Col 2 Blank Col

Somone told me I need to look at DDE for this is this true

Regards,

4

3 回答 3

1

你绝对可以使用 DDE 来做到这一点。DDE 所做的只是模拟用户在 Excel 的菜单、按钮、单元格等处的点击。下面是一个示例,您可以通过宏循环对名称为 have1、have2 和 have3 的 3 个数据集执行此操作。如果您需要更通用的解决方案(未知数量的数据集、不同数量的变量、随机数据集的名称等),则应更新代码,但其“DDE 部分”将基本相同。另一个假设 - 您的 Excel 工作簿应该在代码执行期间打开。虽然它也可以自动化 - 可以启动 Excel 并使用 DDE 本身打开文件。您可以在此处找到关于 DDE 的非常好的介绍,其中详细讨论了所有这些技巧。

data have1;
    input Col1 Col2;
datalines;
1 2
3 4
5 6
;
run;
data have2;
    input Col1 Col2;
datalines;
1 2
3 4
5 6
7 8
;
run;
data have3;
    input Col1 Col2;
datalines;
1 2
3 4
7 8
5 6
9 10
;
run;



%macro xlsout;

/*iterating through your datasets*/
%do i=1 %to 3;

    /*determine number of records in the current dataset*/
    proc sql noprint;
        select  count(*) into :noobs
        from have&i;
    quit;

    /*assign a range on the workbook spreadsheet matching to data in the current dataset*/
    filename range dde "excel|[myworkbook.xls]sas!r1c%eval((&i-1)*3+1):r%left(&noobs)c%eval((&i-1)*3+2)" notab;

    /*put data into selected range*/
    data _null_;
        set have&i;
        file range;
        put Col1 '09'x Col2;
    run;
%end;

%mend xlsout;
%xlsout
于 2014-01-09T04:43:27.377 回答
0

ODS TAGSETS.EXCELXP您可能会通过新的ODS EXCEL(9.4 TS1M1)完成您所要求的。但是,您需要提前安排数据集(即,将它们合并在一起或转置或诸如此类以获取具有正确列的数据集),或者使用PROC REPORT或其他一些程序以正确的格式获取它们。

于 2014-01-09T05:18:43.460 回答
0

你不能用 SAS 完全做到这一点(DDE 可能是可能的)。我建议看看 SaviCells Pro。

http://www.sascommunity.org/wiki/SaviCells

http://www.savian.net/utilities.html

于 2014-01-09T04:14:14.070 回答