Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6819851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:21:19+00:00 2026-05-26T21:21:19+00:00

I usually have a sas macro code which automatically run macros Save As and

  • 0

I usually have a sas macro code which automatically run macros “Save As” and “Close file” in the excel spreadsheet on running the sas code and after populating the data into the excel file.

The problem I have is that the excel file I have right now has certain macros which I cant edit becuase they are password protected and neither can I add any “Save As” and “Close file” macro in it. Is there a way to directly “Save As” and “Close file” with the help of sas and without using the macro.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:21:20+00:00Added an answer on May 26, 2026 at 9:21 pm

    Sure can. You can use DDE to achieve that. Below are 3 macros that should do exactly what you ask. Add them to your SAS autocall macro library:

    /******************************************************************************
    ** PROGRAM:  MACRO.DDE_SAVE_AND_CLOSE.SAS
    **
    ** DESCRIPTION: SAVES THE CURRENT EXCEL FILE AND THEN CLOSES IT.  IF THE FILE
    **              ALREADY EXISTS IT WILL BE OVERWRITTEN.
    **
    ** PARAMETERS: iSAVEAS: THE DESTINATION FILENAME TO SAVE TO.
    **             iType  : (OPTIONAL. DEFAULT=BLANK). 
    **                      BLANK = XL DEFAULT SAVE TYPE
    **                          1 = XLS DOC - OLD SCHOOL! PRE OFFICE 2007?
    **                         44 = HTML - PRETTY COOL! CHECK IT OUT... 
    **                         51 = XLSX DOC - OFFICE 2007 ONWARDS COMPATIBLE?
    **                         57 = PDF
    ** 
    ** NOTES:  IF YOU ARE GETTING A DDE ERROR WHEN RUNNING THIS MACRO THEN DOUBLE
    **         CHECK YOU HAVE PERMISSIONS TO SAVE WHERE YOU ARE TRYING TO SAVE THE
    **         FILE.
    ** 
    *******************************************************************************
    ** VERSION:
    ** 1.0 ON: 01APR10 BY: RP
    **     CREATED.  
    ** 1.1 ON: 19MAY10 BY: RP
    **     ADDED ITYPE OPTION.
    ** 1.2 ON: 20JUL10 BY: RP
    **     DELAYED TURNING ERROR BACK ON AS WAS GETTING UNNECESSARY ERRORS IN 
    **     OFFICE07
    ** 1.3 ON: 17AUG10 BY: RP
    **     CHANGED TO FILE. CLOSE AS IT WOULD CLOSE TWO WORKBOOKS BEFORE.
    ** 1.4 ON: 21JUL11 BY: RP
    **     STOPPED E-R-R-O-R LITERAL FROM SHOWING IN LOG
    ******************************************************************************/
    
    %macro dde_save_and_close(iSaveAs=,iType=);
      %local iDocTypeClause;
    
      %let iDocTypeClause=;
      %if "&iType" ne "" %then %do;
        %let iDocTypeClause=,&iType;
      %end;
    
      filename cmdexcel dde 'excel|system';
      data _null_;
        length str_line $200;
        file cmdexcel;
    
        put '[error(false)]';
        put "%str([save.as(%"&iSaveAs%"&iDocTypeClause)])";
        put '[file.close(0)]';
    
        str_line = cats("[e","rror(true)]");
        put str_line;
      run;
      filename cmdexcel clear;
    
    %mend;
    /*%dde_save_and_close(iSaveAs=d:\rrobxltest, iType=44);*/
    
    
    /******************************************************************************
    ** PROGRAM:  MACRO.DDE_SAVE_AS.SAS
    **
    ** DESCRIPTION: SAVES THE CURRENT EXCEL FILE.  IF THE FILE
    **              ALREADY EXISTS IT WILL BE OVERWRITTEN.
    **
    ** PARAMETERS: iSAVEAS: THE DESTINATION FILENAME TO SAVE TO.
    **             iType  : (OPTIONAL. DEFAULT=BLANK). 
    **                      BLANK = XL DEFAULT SAVE TYPE
    **                          1 = XLS DOC - OLD SCHOOL! PRE OFFICE 2007?
    **                         44 = HTML - PRETTY COOL! CHECK IT OUT... 
    **                         51 = XLSX DOC - OFFICE 2007 ONWARDS COMPATIBLE?
    **                         57 = PDF
    ** 
    ** NOTES:  IF YOU ARE GETTING A DDE ERROR WHEN RUNNING THIS MACRO THEN DOUBLE
    **         CHECK YOU HAVE PERMISSIONS TO SAVE WHERE YOU ARE TRYING TO SAVE THE
    **         FILE.
    ** 
    *******************************************************************************
    ** VERSION:
    ** 1.0 ON: 01APR10 BY: RP
    **     CREATED.  
    ******************************************************************************/
    
    %macro dde_save_as(iSaveAs=,iType=);
      %local iDocTypeClause;
    
      %let iDocTypeClause=;
      %if "&iType" ne "" %then %do;
        %let iDocTypeClause=,&iType;
      %end;
    
      filename cmdexcel dde 'excel|system';
      data _null_;
        length str_line $200;
        file cmdexcel;
        put '[error(false)]';
        put "%str([save.as(%"&iSaveAs%"&iDocTypeClause)])";
        str_line = cats("[e","rror(true)]");
        put str_line;
      run;
      filename cmdexcel clear;
    
    %mend;
    /*%dde_save_as(iSaveAs=d:\rrobxltest, iType=44);*/
    
    /******************************************************************************
    ** PROGRAM:  MACRO.DDE_CLOSE_WITHOUT_SAVE.SAS
    **
    ** DESCRIPTION: CLOSES EXCEL WITHOUT SAVING THE FILE
    **
    ** PARAMETERS: NONE
    ** 
    *******************************************************************************
    ** VERSION:
    ** 1.0 ON: 18MAY10 BY: RP
    **     CREATED.  
    ******************************************************************************/
    
    %macro dde_close_without_save();
      filename cmdexcel dde 'excel|system';
      data _null_;
        file cmdexcel;
        put '[close(0)]';
      run;
      filename cmdexcel clear;
    %mend;
    /*%dde_close_without_save;*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run an MSI (without parameters) I usually have to click my way
When performing many inserts into a database I would usually have code like this:
In a Python system for which I develop, we usually have this module structure.
When I want to get to a web, I usually have to do code
I run an ASP.NET application on IIS 6.0. Usually I have compression turned on
I usually have jQuery code that is page specific along with a handful of
I usually have a config-file with some global variables for database connectivity settings (such
I usually have a config-file with some global variables for database connectivity settings (such
I usually have more then 10 opened application windows. When I write code I
I usually have my structure laid out something like this: <div id=all> <div id=page>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.