SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Writing MS Office and other binary files

Reply
Contributor
Posts: 31

Writing MS Office and other binary files

Hi,

At my presentation on using the DATA Step as a POP3 mail client somebody asked how to deal with attachments. For text-based attachments that is no problem. Binary files are more complicated. First you have to decode them (back from Base64 to binary) and then file them. Decoding is a piece of cake, but the filing part is giving me a headache. I could not open it.

Then I tried to read an Excel file (*.xls) and write it out again, just with INPUT; PUT _INFILE_; I could not open the copied file, although in the properties it looks identical (at least in byte count).
Next I did a comparison by reading the original file and the copy file and compare them byte by byte. No difference to see.

So I assume that there are certain hidden elements in those binary files that are not read or rewritten in this process.

Any suggestion what I might be missing and how to solve it?
Super Contributor
Posts: 291

Re: Writing MS Office and other binary files

please post your code ...
Contributor
Posts: 31

Re: Writing MS Office and other binary files

This is the code I used for copying:

filename orig 'e:\sgf2009\test1.xls' recfm=v lrecl=32767 ignoredoseof;
filename copy 'e:\sgf2009\test2.xls' recfm=v lrecl=32767 ignoredoseof;
data _null_;
infile orig ;
input;
file copy;
put _infile_;
run;
filename orig clear;
filename copy clear;

I think the problem is that the filename statement does not handle the file attribute settings under windows and I don't see any options by which I could set them.
Although the contents of the files is identical, the properties windows are not. The original shows 3 tabs (General, Custom, Summary), the copy shows only one (General)

rgds Erik
Super Contributor
Posts: 291

Re: Writing MS Office and other binary files

how about

data _null_;
call system ('copy c:\temp\Orig.xls c:\temp\Copy.xls');
run;

?
Contributor
Posts: 31

Re: Writing MS Office and other binary files

Yes, but that does not solve my problem.

The final step is not the copy, that was only a test, trying to figure out what went wrong.

The idea is to decode and file a BASE64 mail attachment. So I need to do it in a DATA step.
Super Contributor
Posts: 291

Re: Writing MS Office and other binary files

and this option doesn't work for you?

attach=("c:\temp\test.xls"
ct="application/octet-stream");
Contributor
Posts: 31

Re: Writing MS Office and other binary files

Bill,

I have given up on finding out why the copying did not work, but I have been able to reach my original goal: converting a BASE64 encoded file into its original binary status.

If you want to do it in a DATA step, with FILE and PUT statements, the trick is that you have to write them as one continuous data stream. To do that you define a logical record length which is bigger than the biggest attachment you are handling. I tried LRECL of more than 1 MB and you use a trailing @ in the PUT statement.

The alternative is to use an external program like base64.exe and use a CALL SYSTEM to execute it.

Thanks to your interest in the matter!
Post a Question
Discussion Stats
  • 6 replies
  • 207 views
  • 0 likes
  • 2 in conversation