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

Hello guys,

I know we can calculate the dataset size using PROC SQL and some other way ,but is there any way to calculate a file size for physical file which is not imported in to the SAS system? Any predefined function for that to calculate the the file size for the given path??

note: I am using SAS EG 7.1

 

Please suggest me some ideas to achieve that 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Peter_C
Rhodochrosite | Level 12
Should work in a data step without %sysfunc.
As default type for new variables is numeric predefine filerf as char....

Data _null_ ;
Length filerf $8 filesizestr $40 ;
Rc = filename( filerf , '<file path and name>' ) ;
Fid= fopen( filerf );
Filesizestr = finfo( fid, 'File Size (bytes)' );
Put (_all_)(=/);
Run ;

beware this remains untested as EG doesn't yet run on my android

View solution in original post

13 REPLIES 13
RW9
Diamond | Level 26 RW9
Diamond | Level 26

If its a SAS dataset, then you have the file size in sashelp.vtable.  If its not, then you would need to rely on operating system functions to return that information.  For instance, the x command on Windows can execute a dir command which can list a folders into a dataset, something like:

filename tmp pipe 'dir "c:\test\*.*"';

data want;
  length buff $200;
  infile tmp dlm="¬";
  input buff $;
run;

You can parse out information from that.  Unix has its own commands.

Pooja98
Fluorite | Level 6

Can anyone explain this code in detail manner?

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please avoid posting new questions in very old answered questions.  Open a new thread if you have a new question.

In terms of my code, the pipe is a means of sending output from a command sent to the operating system (in this case a dir command), back to a dataset.  So the filename sets this up, the datastep and infile actually run the command in your OS, and then the output is captured and read back in via the input.

Peter_C
Rhodochrosite | Level 12
Is there not function FATTR() ?
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Do you mean this:

http://support.sas.com/documentation/cdl/en/hostvms/62450/HTML/default/viewer.htm#alp-func-fileattr....

 

Doesn't seem to work on our SAS, is it OS specific?  Only other thing I could find was this:

https://support.sas.com/documentation/onlinedoc/sasc/doc700/html/lr1/z2055006.htm

 

Would be interested in seeing some doc on it.

Peter_C
Rhodochrosite | Level 12
No, it is FINFO()
arunrami
Pyrite | Level 9
Hi , Could you please Tell me the syntax for it I tried some thing like below, am not getting any value for file size variable.

%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
'<Filepath>'));
%let fid=%sysfunc(fopen(&filrf));

data A;
File_Size=finfo(&fid,'File size');
run;
arunrami
Pyrite | Level 9

Thanks for your help, Finally here its working code. But can you tell why its not writing the File_size value if we don't use %sysfunc??

 

%macro FileSize;
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
   '<FilePath>'));
%let fid=%sysfunc(fopen(&filrf));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%put &Bytes;
%mend;
%FileSize; 


data A;
*File_Size=SYMGET('Bytes');
File_Size=%sysfunc(finfo(&fid,File Size (bytes)));
run;
Peter_C
Rhodochrosite | Level 12
The function FINFO can provide the file size info on Unix and Windows (for which the doc is at http://support.sas.com/documentation/cdl/en/hostwin/63285/HTML/default/win-func-finfo.htm#a002563061
)
Peter_C
Rhodochrosite | Level 12
apples about FATTR
That was part of my favourite display manager dependant module FSEDIT
Peter_C
Rhodochrosite | Level 12
B**** autocorrect for apples read "apols"
Peter_C
Rhodochrosite | Level 12
Should work in a data step without %sysfunc.
As default type for new variables is numeric predefine filerf as char....

Data _null_ ;
Length filerf $8 filesizestr $40 ;
Rc = filename( filerf , '<file path and name>' ) ;
Fid= fopen( filerf );
Filesizestr = finfo( fid, 'File Size (bytes)' );
Put (_all_)(=/);
Run ;

beware this remains untested as EG doesn't yet run on my android
Peter_C
Rhodochrosite | Level 12
beware also leaving files open
On re-running the step
FID= should reveal increasing number
But that won't be the only impact

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 9290 views
  • 5 likes
  • 4 in conversation