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


Hi,

Looking through Art Carpenter's Innovative SAS Techniques, on page 7 he shows a technique for updating a sheet in an excel workbook.  In this example he used an Office 97/2003 type workbook (.xls).

Tried to duplicate this with a current style workbook in Windows SAS 9.2 and got an error.

  1. I created a test workbook (test.xlsx) with a single sheet named 'test'.
  2. I then used the following libname to get to it:
    libname testx excel '...path to sheet\test.xlsx' scan_text=no;
  3. Ran a proc datasets to delete the file (had to use a $ after the name--it couldn't find the sheet name just as 'test'):
    proc datasets library=testx nolist;
      delete 'test$'n;
      quit;
  4. Then used a simple data step to try to replace it:
    data testx.'test$'n;
    set temp;
    run;

The error I got back was:

ERROR: The MS Excel table test$ has been opened for OUTPUT.  This table already

         exists, or there is a name conflict with an existing object.  This table

         will not be replaced.  This engine does not support the REPLACE option.

NOTE: The SAS System stopped processing this step because of errors.

Suggestions?

Thanks much!

--Ben

1 ACCEPTED SOLUTION

Accepted Solutions
BenConner
Pyrite | Level 9

Found the answer to the question I posed; apparently the technique illustrated is very specific to .xls formatted Excel files.  I ended up using a Proc Export with a Replace option, but had to name the tab and the columns on that tab with a named range identical to the tab name.  Example:

Proc Export data=work.scores

   outfile='c:\temp\classes.xlsx'

   dbms=EXCEL

   Replace;

  sheet='classscores';

run;

The tab classscores had a named range of classscores defined on it as well.  SAS was able to delete and replace the contents nicely.

Many thanks to Sandy O in SAS' tech support for pointing me in the right direction.

--Ben

View solution in original post

1 REPLY 1
BenConner
Pyrite | Level 9

Found the answer to the question I posed; apparently the technique illustrated is very specific to .xls formatted Excel files.  I ended up using a Proc Export with a Replace option, but had to name the tab and the columns on that tab with a named range identical to the tab name.  Example:

Proc Export data=work.scores

   outfile='c:\temp\classes.xlsx'

   dbms=EXCEL

   Replace;

  sheet='classscores';

run;

The tab classscores had a named range of classscores defined on it as well.  SAS was able to delete and replace the contents nicely.

Many thanks to Sandy O in SAS' tech support for pointing me in the right direction.

--Ben

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Discussion stats
  • 1 reply
  • 7219 views
  • 0 likes
  • 1 in conversation