BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
IanWakeling
Barite | Level 11

I am attempting (for the first time) to read from binary data files directly into IML.  Is there a way to get the size of the file I have opened with INFILE in bytes?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I don't usually use the INFILE statement or deal with binary files, but I think the process is exactly the same as for the DATA step. Remember that you can call most Base SAS functions from SAS/IML. In particular, you can call the FINFO function and other file-related functions. Adapting the doc example to IML gives:

 

filename fref "C:\temp\myfile";
proc iml;
fid=fopen('fref');
/* for my OS, what FINFO options are available? */
infonum=foptnum(fid);
infoname = foptname(fid, 1:infonum);
print infoname;

/* looks like the 4th element is the file size on Windows */
size = finfo(fid, infoname[4]);
print size;
close=fclose(fid);

View solution in original post

3 REPLIES 3
Rick_SAS
SAS Super FREQ

I don't usually use the INFILE statement or deal with binary files, but I think the process is exactly the same as for the DATA step. Remember that you can call most Base SAS functions from SAS/IML. In particular, you can call the FINFO function and other file-related functions. Adapting the doc example to IML gives:

 

filename fref "C:\temp\myfile";
proc iml;
fid=fopen('fref');
/* for my OS, what FINFO options are available? */
infonum=foptnum(fid);
infoname = foptname(fid, 1:infonum);
print infoname;

/* looks like the 4th element is the file size on Windows */
size = finfo(fid, infoname[4]);
print size;
close=fclose(fid);
IanWakeling
Barite | Level 11

Thanks Rick,  that works nicely.

 

Caution to others using this, the file size is returned as a character string.

Ksharp
Super User

As Rick pointed out ,it is more like a data step question than a IML question.

 

filename x 'c:\temp\x.txt';
proc sql;
create table temp as
select *
 from dictionary.EXTFILES
 where fileref='X';
quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 1355 views
  • 1 like
  • 3 in conversation