I generate a SAS program that updates specific cells in an Excel spreadsheet. I am using the following syntax:
options noxwait noxsync;
filename update1 dde 'excel|worksheet1!r107c5';
filename update2 dde 'excel|worksheet1!r107c7';
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.
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.
Test this on a Windows command line:
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.
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.