BookmarkSubscribeRSS Feed
sheru
Fluorite | Level 6


 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

5 REPLIES 5
Cynthia_sas
SAS Super FREQ

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

sheru
Fluorite | Level 6
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.
sheru
Fluorite | Level 6

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

Cynthia_sas
SAS Super FREQ

Hi:

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

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 5623 views
  • 6 likes
  • 3 in conversation