AFAIK, a spreadsheet is always write-protected if opened by another user, unless this user themselves has opened it as write-protected.
It's a similar issue in SAS: if a user has a dataset open in file viewer or any other SAS method, you can't write to it.
What are you actually trying to achieve with all this, what is your final goal (Maxim 43)?
I have a 'live' sales data table which updates in real time with sales values. Every 5 minutes I want to get the sum of all sales made and then append to a secondary table which is storing all historical records. Rather than someone clicking run every 5 mins I want to automate the process - which I think I've achieved in the code below. However, I also need to be able to see how the sales figures in the 'master' data table are increasing and this is what I don't know how to do while the macro loop is still running. Ideally I would like the 'master' data in a spreadsheet so I can have a graph/chart updating as the data updates.
%macro sales ;
%let count=0 ;
%do %until (&count=2) ;
%let count=%eval(&count+1);
/* Latest snapshot */
data interim ;
set livesales;
format runtime time. ;
runtime = time() ;
run ;
/* Append to previous records */
data master ;
set master interim ;
run ;
/* Delay next run for 5 minutes */
data _null_ ;
rc=sleep(300,1) ;
run ;
%end ;
%mend ;
%sales ;
Have the SAS program create a web page (ODS HTML) within the loop that has the HTTP META tag REFRESH set to 300 (use the METATEXT option in the ODS HTML statement). Then you open the page once in your browser, and it automatically refreshes every 5 minutes.
What would be the advantage of specifically writing to a spreadsheet in this context?
Assuming your loops operate in the time interval you describe you would not have time to modify the results for any run. If you have more columns or rows written to than the open width by the time you try to read anything you are likely running out of time just scrolling up/down or left/right.
The only approach that I think has any chance would be 1) open the spreadsheet before anything else for DDE and then 2) use the DDE commands to update cells in the "export" section.
Conerns: DDE is not actively supported, only available for specific applications and operating systems (Microsoft applications like Excel / Windows), is very sensitive to the version of the application for some actions, not updated with promise the next "update" to Excel won't remove the links, and probably a few other things that don't come to mind as the last time I touched DDE was 5 years ago.
I learned a lot, thanks
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.