Desktop productivity for business analysts and programmers

how to password protect excel files from SAS EG?

Reply
Occasional Contributor
Posts: 7

how to password protect excel files from SAS EG?


 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("'"&amp;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("'"&amp;xlsfile2"'",1,"'"&amp;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

SAS Super FREQ
Posts: 8,716

Re: how to password protect excel files from SAS EG?

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

Occasional Contributor
Posts: 7

Re: how to password protect excel files from SAS EG?

Hello Cynthia@sas, Thank you. i know we cant work with DDE any more in EG, I am trying to know is there any other way we can generate password protected excel files from SAS.
Respected Advisor
Posts: 3,060

Re: how to password protect excel files from SAS EG?

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

Occasional Contributor
Posts: 7

Re: how to password protect excel files from SAS EG?

Hello SASKiwi, Thank you for the article, i will try to implement it and update the results.

SAS Super FREQ
Posts: 8,716

Re: how to password protect excel files from SAS EG?

Hi:

  You may need help from your SAS Admin to allow the X command. That is usually disabled for EG users.

cynthia

Ask a Question
Discussion stats
  • 5 replies
  • 1810 views
  • 6 likes
  • 3 in conversation