- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do I import a password protected Excel document? My proc imports works fine any non-password protected excel doc. I tried adding 'password = ' to the code below, but got an error with the password= option. Any input will be greatly appreciated.
Thanks!
proc import out= ssn1
datafile= "&Ssn_FILE"
dbms=EXCEL replace;
mixed = yes;
sheet= "Sheet1";
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have you tried passing the password through the PIPE engine on the FILENAME statement? That is just a guess.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Maybe you need build a ODBC connection for that xls file,because SAS treat Excel file as a library,but it is too troubled.Or recommend you to use password to open that Excel file and File-> Save as->xls file to make a xls file without password.
Ksharp
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The old time solution is DDE.
http://support.sas.com/forums/thread.jspa?messageID=35783诇
>
http://support.sas.com/forums/thread.jspa?messageID=35783诇
Oleg.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The code below sets the password. I'm not the author of this code. I've find it somewhere and It was very helpful as a solution of some tasks in different modifications. For example, I've modified it to rename Excel sheets.
You can change the VBA code to disable password protection.
[pre]
filename IN '.\book1.xls';
filename OUT '.\book1PW.xls';
%let PW = PWvalue;
data _null_;
length script filevar command workbook1 workbook2 $256 pw $16;
script = catx('\',pathname('WORK'),'PASSWORD.vbs');
filevar = script; workbook1 = pathname('in');
workbook2 = pathname('out');
pw = symget('PW');
file dummy1 filevar=filevar;
put 'Const ' workbook1=$quote256.;
put 'Const ' workbook2=$quote256.;
put 'Const ' pw=$quote18.;
put 'Set objExcel = CreateObject("Excel.Application")';
put 'objExcel.Visible = FALSE';
put 'objExcel.DisplayAlerts = FALSE';
put 'Set objWorkbook = objExcel.Workbooks.Open(workbook1)';
put 'objWorkbook.SaveAs workbook2,,pw';
put 'objExcel.Quit';
/* close the script file by opening another file */
filevar = catx('\',pathname('WORK'),'DUMMY2.vbs');
file dummy1 filevar=filevar;
/* look at the script, not necessary but may be useful */
infile dummy3 filevar=script end=eof;
do _n_ = 1 by 1 until(eof); input;
putlog 'NOTE: ' _n_ 3. +1 _infile_; end;
/* call the script */
command = catx(' ','cscript',quote(strip(script)));
infile dummy4 pipe filevar=command end=eof;
do until(eof);
input ;
putlog _infile_;
end;
stop;
run;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you agian!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Oleg. I realize that this post is from a previous decade but here goes anyway. I am ultimately trying to read a lot of locked Excel data into a dataset. I am using EG 8.4 and have copied the files to the server. I tried DDE since the files are copied to the server using another one of your examples but the line filename cc dde 'Excel|System'; throws this error: ERROR: Invalid device type.ERROR: Error in the FILENAME statement.
So I was trying the VBA script option you mention, modified to read the file with password, unprotect it, and re-save without password. But I'm getting the error that it doesn't understand the C-shell command: /bin/bash: cscript: command not found
Any suggestions? If not, I am going to just work outside of SAS. It will just be slow...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
DDE is only possible if you are running SAS on your PC and the Excel file is accessible from the PC. Sounds like your EG uses a remote Unix SAS server so it isn't going to work and VBA wont run on Unix.
The quick fix is to create an un-passworded version and upload that to your SAS server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I appreciate this post is 12 years old, but my team finally added this feature to Data Controller today!
Just upload the excel, enter the password, approve the change, and your password-protected excel data is now in your target SAS table ready to process.
Works on ALL versions of SAS (Viya, EBI, Base) and is free for up to 5 users.