BookmarkSubscribeRSS Feed
Calcite | Level 5

I generate a SAS program that updates specific cells in an Excel spreadsheet. I am using the following syntax:


options noxwait noxsync;
x '"filename.xlsx"';
data _null_;
filename update1 dde 'excel|worksheet1!r107c5';
file update1;
put '4938';
filename update2 dde 'excel|worksheet1!r107c7';
file update2;
put '3146';


The spreadsheet is updated, but the Excel/worksheet1 must be open and highlighted when the SAS program is executed. If it isn't, there is an error that SAS can't find the file - it doesn't exist to SAS. 


Is there a method to update the spreadsheet without opening it first? I would like to schedule the job and have the spreadsheet updated automatically.




JIm A.



Have you tried calling Excel like this?

x 'excel.exe "c:\MyFolder\filename.xlsx"';

I can only assume you are using SAS on a PC as DDE simply wont work otherwise. Also please note Microsoft has deprecated DDE so you are lucky it is working for you at all.

Calcite | Level 5

You are correct - I am using SAS (9.4 ts1M6) on a PC. Your suggestion doesn't seem to work.


Is there another approach insted of the 'x' and 'dde'?


Test this on a Windows command line:

excel.exe "c:\MyFolder\filename.xlsx"

If it doesn't work from a command line it won't work in SAS. Also check the properties of your Windows shortcut to Excel and change your command test to be the same.  I had to use this to get it working:

"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE"

Your software location could be different.

Opal | Level 21

As already stated DDE is not only limited to Windows but also depreciated since years. On the other hand I'm not aware of any SAS only way that would allow you to update an Excel cell.

If your Excel sheet is just a simple rectangular table (a "data sheet") then the easiest way is to just fully re-create the sheet, but if your sheet contains some complex formatting and layout then that might not be an option.

I started to use Python for such tasks (openpyxl) because it provides the functionality for updating Excel sheets. If the code needs to by dynamic then you can generate such Python code also via SAS and then send it to Python for execution.



Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.


Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 


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
  • 5 replies
  • 4 in conversation