BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sam1231
Obsidian | Level 7

Hi ,

 

i Want to delete excelsheet from excel using sas. Can I do that?

 

How can i use DDE to delete sheet from excel using sas.

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Please go through the instructions in this SAS note to diagnose this error then post your findings: http://support.sas.com/kb/60/356.html

 

Are you using local SAS on your PC? If so then you should refer to your spreadsheet like this:

c:\users\download\report.xlsx

 

View solution in original post

10 REPLIES 10
SASKiwi
PROC Star

Why not use PROC DATASETS? DDE only works if you are running SAS on your PC. PROC DATASETS works on both PCs and remote SAS servers.

 

libname MyExcel EXCEL "MyExcelWorkbook.xlsx";

proc datasets library = MyExcel nolist nowarn;
  delete MySheetName;
  run;
quit;
sam1231
Obsidian | Level 7

thank you for your reply!

 

But it s give me below error.

 

ERROR: Connect: Class not registered ERROR: Error in the LIBNAME statement. 

 

i am using below code:

 

libname MyExcel EXCEL "c/users/download/report.xlsx";

proc datasets library = MyExcel nolist nowarn;
  delete MySheetName;
  run;
quit;





I have PC SERVER FILE installed.
SASKiwi
PROC Star

Please go through the instructions in this SAS note to diagnose this error then post your findings: http://support.sas.com/kb/60/356.html

 

Are you using local SAS on your PC? If so then you should refer to your spreadsheet like this:

c:\users\download\report.xlsx

 

LuciaCekanakova
Obsidian | Level 7

Hi,

I've tried your code to delete a sheet from excel - it runs without errors, but the sheet is not deleted from the excel file. Any idea why?

 

Thanks!

Vince_SAS
Rhodochrosite | Level 12

Can you post the exact code that you used, and the messages that you see in the log?

 

Vince DelGobbo

SAS R&D

LuciaCekanakova
Obsidian | Level 7

My code:

libname MyExcel EXCEL "C:\excel_file.xlsx";

proc datasets library = MyExcel nolist nowarn;
  delete Sheet5;
  run;
quit;

libname myexcel;

And the whole log:

 

NOTE: Copyright (c) 2016 by SAS Institute Inc., Cary, NC, USA.
NOTE: SAS (r) Proprietary Software 9.4 (TS1M6 MBCS3170)
Licensed to SAS INTERNAL 940 19W04 WX6+ FULL PROD+GRID, Site 70146517.
NOTE: This session is executing on the X64_10PRO platform.

 

NOTE: Analytical products:

SAS/STAT 15.1
SAS/ETS 15.1
SAS/OR 15.1
SAS/IML 15.1
SAS/QC 14.3

NOTE: Additional host information:

X64_10PRO WIN 10.0.16299 Workstation

NOTE: SAS initialization used:
real time 3.34 seconds
cpu time 2.84 seconds

NOTE: Unable to open SASUSER.REGSTRY. WORK.REGSTRY will be opened instead.
NOTE: All registry changes will be lost at the end of the session.
WARNING: Unable to copy SASUSER registry to WORK registry. Because of this,
WARNING: you will not see registry customizations during this session.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.
NOTE: This SAS session is using a registry in WORK. All changes will be lost at the end of
NOTE: this session.
NOTE: Unable to open SASUSER.PROFILE. WORK.PROFILE will be opened instead.
NOTE: All profile changes will be lost at the end of the session.

1 libname MyExcel EXCEL "C:\excel_file.xlsx";
NOTE: Libref MYEXCEL was successfully assigned as follows:
Engine: EXCEL
Physical Name: C:\excel_file.xlsx
2
3 proc datasets library = MyExcel nolist nowarn;
NOTE: Writing HTML Body file: sashtml.htm
4 delete Sheet5;
5 run;

6 quit;

NOTE: PROCEDURE DATASETS used (Total process time):
real time 1.05 seconds
cpu time 0.79 seconds


7
8 libname myexcel;
NOTE: Libref MYEXCEL has been deassigned.

 

 

 

Vince_SAS
Rhodochrosite | Level 12

Run this code and examine the output:

 

options validmemname=extend;

libname MyExcel EXCEL 'C:\excel_file.xlsx'; proc contents data=MyExcel._all_; run; quit;

 

The table name is MYEXCEL.'Sheet5$'n and 'Sheet5$'n is what you need to use in your code:

 

options validmemname=extend;

libname MyExcel EXCEL 'C:\excel_file.xlsx'; proc datasets library = MyExcel nolist nowarn; delete 'Sheet5$'n; run; quit; libname MyExcel;

 

The EXCEL engine deletes the contents of the worksheet, but does not remove the now empty worksheet from the file.

 

Vince DelGobbo

SAS R&D

LuciaCekanakova
Obsidian | Level 7

Hi,

it works now, thank you!

Too bad it doesn't delete the sheet itself though.

 

Lucia

Ksharp
Super User

Try another engine.

 

libname MyExcel xlsx  "c/users/download/report.xlsx";

 

Vince_SAS
Rhodochrosite | Level 12

This error happens when the bitness of SAS does not match the bitness of Microsoft Excel.

 

Try using the XLSX engine, like @Ksharp suggested.

 

Vince DelGobbo

SAS R&D

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 5278 views
  • 8 likes
  • 5 in conversation