- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Can anyone explain this code in detail manner?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you mean this:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let filrf=myfile;
%let rc=%sysfunc(filename(filrf,
'<Filepath>'));
%let fid=%sysfunc(fopen(&filrf));
data A;
File_Size=finfo(&fid,'File size');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That was part of my favourite display manager dependant module FSEDIT
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
On re-running the step
FID= should reveal increasing number
But that won't be the only impact