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;


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1092 views
  • 0 likes
  • 2 in conversation