i used to create password protected excel files in base SAS using DDE. Can any one guide me how to create password protected excel files in SAS EG, following code( got it from SAS support page) which i used in base SAS, this code doesn't work in SAS EG as DDE is not supported on SAS EG. my client is using SAS EG 6.1 which runs on SAS 9.4
%macro writpass(xlsfile1,xlsfile2,password,sasfile,deleteit);
options macrogen symbolgen mprint nocaps;
options noxwait noxsync;
* First, SAS writes an Excel file here without the password. *;
proc export outfile="&xlsfile1" data=&sasfile dbms=excel replace;
run;
quit;
* This next routine starts the Excel application. *;
filename cmds dde 'excel|system';
x "'C:\Program Files\Microsoft Office\Office11\excel.exe'";
data null;
x=sleep(3);
run;
* SAS opens the Excel worksheet with its password. ;<br>filename cmds dde 'excel|system';<br>data null;<br> file cmds;<br> put '[open("'"&xlsfile1"'")]';<br>run;<br> SAS saves the file without the password. ;<br>data null;<br> file cmds;<br> put '[error("false")]';<br> put '[save.as("'"&xlsfile2"'",1,"'"&password"'")]'; <br> put '[quit]';<br>run;</code></p><p><code> Then SAS destroys the Excel file that is not password protected. *;
%if &deleteit=yes %then %do;
systask command "del ""&xlsfile1"" ";
%end;
%mend writpass;
Thanks
Hi:
You have answered your own question when you said: "this code doesn't work in SAS EG as DDE is not supported on SAS EG." Here's a blog post explaining why DDE is not supported with EG:
http://blogs.sas.com/content/sasdummy/2014/10/14/dde-is-doa/
You might investigate creating the file and then writing an Excel macro or VB Script to set the password.
cynthia
This might be helpful. It would probably work for EXPORTed spreadsheets as well.
48682 - Add password protection to Excel workbooks that are generated using the ExcelXP tagset
Hello SASKiwi, Thank you for the article, i will try to implement it and update the results.
Hi:
You may need help from your SAS Admin to allow the X command. That is usually disabled for EG users.
cynthia
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.