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

发布于 2024-09-26 16:33:06 字数 294 浏览 4 评论 0原文

我有以下宏:

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

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

I have the following macro:

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

My problem is that sometimes this macro doesn't delete the tab if it already exists. Is there anyway, from SAS, that I can check if a tab exists and delete it if it does?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷…雨湿花 2024-10-03 16:33:06

您可以使用下面的宏通过 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);

You can use the below macro to delete a worksheet in Excel via DDE. It requires that the workbook that you want to delete the sheet from is the currently active workbook in 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);
只是一片海 2024-10-03 16:33:06
proc sql; drop table <NAME OF EXCEL TAB>; quit;
proc sql; drop table <NAME OF EXCEL TAB>; quit;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文