如何从SAS删除excel工作簿的选项卡?

时间:2010-10-04 16:45:19

标签: excel sas

我有以下宏:

%macro export_set_excel(data,tabname);
    PROC EXPORT DATA= &data. OUTFILE= "&results." DBMS=EXCEL REPLACE;
            SHEET=&tabname.; 
        RUN;
%mend export_set_excel;

我的问题是,如果已经存在,有时此宏不会删除该选项卡。无论如何,从SAS,我可以检查是否存在选项卡,如果存在则将其删除?

2 个答案:

答案 0 :(得分:4)

您可以使用以下宏通过DDE删除Excel中的工作表。它要求您要从中删除工作表的工作簿是Excel中当前活动的工作簿。

/******************************************************************************
** PROGRAM:  MACRO.DDE_WORKSHEET_DELETE.SAS
**
** DESCRIPTION: DELETES THE SPECIFIED WORKSHEET FROM THE ACTIVE WORKBOOK IN 
**              EXCEL.
**
** PARAMETERS: iWORKSHEET: THE NAME OF THE WORKSHEET.  INCLUDE ANY SPACES THAT
**                         MAY BE CONTAINED IN THE NAME OF THE WORKSHEET.
**                         
** NOTES: SEE OTHER DDE_MACRO* FILES FOR MORE INFORMATION.
**
*******************************************************************************
** VERSION:
** 1.0 ON: 01APR10 BY: RP
**     CREATED.  
******************************************************************************/
%macro dde_worksheet_delete(iWorksheet=);
  filename cmdexcel dde 'excel|system';
  data _null_;
    file cmdexcel;

    /*
    ** DELETE WORKSHEET.  NEED TO TEMPORARILY TURN 
    ** OFF ERROR CHECKING TO SUPPRESS PROMPT.
    */
    put '[error(false)]';
    put "%str([workbook.delete(%"&iWorksheet%")])";
    put '[error(true)]';
  run;
  filename cmdexcel clear;
%mend;


/*
** EXAMPLE USAGE:
*/
%dde_worksheet_delete(iWorksheet=Sheet1);

答案 1 :(得分:3)

proc sql; drop table <NAME OF EXCEL TAB>; quit;