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?
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);
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);
Thanks Rick, that works nicely.
Caution to others using this, the file size is returned as a character string.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.