BookmarkSubscribeRSS Feed
jlam2
Calcite | Level 5

Hello,

I have an excel file with multiple sheets: Sheet1, Sheet2, Sheet3, Sheet4. I want to run a weekly report that replaces information on Sheet1 but keeps Sheet2, Sheet3, and Sheet4 as is. Currently, my code below replaces Sheet1 with new information but deletes Sheets2-4 in the newly exported file. Can anyone help me figure out what I should code for this, please? 

PROC EXPORT data=new
     OUTFILE = "T:\filename.xlsx"
     DBMS = EXCEL REPLACE;
     SHEET = "Sheet1";
     NEWFILE = YES;
RUN;

1 REPLY 1
Reeza
Super User

Have you tried using a LIBNAME approach instead? I noticed you're using DBMS=EXCEL which is really old, if you're on an older version of SAS this may not work. 

 

libname myFile xlsx 'path to xlsx file';

proc sql;
drop table myFile.Sheet1;
quit;

data myFile.Sheet1;
set new;
run;

libname myFile;

@jlam2 wrote:

Hello,

I have an excel file with multiple sheets: Sheet1, Sheet2, Sheet3, Sheet4. I want to run a weekly report that replaces information on Sheet1 but keeps Sheet2, Sheet3, and Sheet4 as is. Currently, my code below replaces Sheet1 with new information but deletes Sheets2-4 in the newly exported file. Can anyone help me figure out what I should code for this, please? 

PROC EXPORT data=new
     OUTFILE = "T:\filename.xlsx"
     DBMS = EXCEL REPLACE;
     SHEET = "Sheet1";
     NEWFILE = YES;
RUN;


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1130 views
  • 0 likes
  • 2 in conversation