BookmarkSubscribeRSS Feed
Jima
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';
run;

 

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.

 

Thanks...

 

JIm A.

 

5 REPLIES 5
SASKiwi
PROC Star

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.

Jima
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'?

SASKiwi
PROC Star

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.

Patrick
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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1015 views
  • 0 likes
  • 4 in conversation