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
Opal | Level 21

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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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