Hello everyone, I'm new to programming in sas and I would like to obtain in tables the weight/size that my .xlsx, .csv, etc. files occupy, inside the "Files" folder on the sas server as shown in the image below .
To do the same but in "Libraries" I have used the dictionary.tables functions offered by SAS, but I don't know if there is a similar function to see the size of the different types of files within SAS.
Could someone guide me about this? I will be very grateful, thanks in advance
Usually, this folder (which leads directly into the SAS server's filesystem) is configured to start at the home directory of the user.
See if this ingenious code (with regards to it's creator, @Tom) does it for you:
data filelist;
length dname filename $256 dir level 8 lastmod size 8;
format lastmod datetime20.;
input dname;
retain filename ' ' level 0 dir 1;
cards4;
$HOME
;;;;
data filelist;
modify filelist;
rc1=filename('tmp',catx('/',dname,filename));
rc2=dopen('tmp');
dir = not not rc2;
if not dir then do;
fid=fopen('tmp','i',0,'b');
lastmod=input(finfo(fid,foptname(fid,5)),NLDATM100.);
size=input(finfo(fid,foptname(fid,6)),32.);
fid=fclose(fid);
end;
else do;
dname=catx('/',dname,filename);
filename=' ';
lastmod=input(dinfo(rc2,doptname(rc2,5)),NLDATM100.);
end;
replace;
if dir;
level=level+1;
do i=1 to dnum(rc2);
filename=dread(rc2,i);
output;
end;
rc3=dclose(rc2);
run;
If it doesn't, ask your SAS administrator where the navigation path is set to by the server configuration in SAS metadata, so you can use this instead of $HOME in the first step.
Usually, this folder (which leads directly into the SAS server's filesystem) is configured to start at the home directory of the user.
See if this ingenious code (with regards to it's creator, @Tom) does it for you:
data filelist;
length dname filename $256 dir level 8 lastmod size 8;
format lastmod datetime20.;
input dname;
retain filename ' ' level 0 dir 1;
cards4;
$HOME
;;;;
data filelist;
modify filelist;
rc1=filename('tmp',catx('/',dname,filename));
rc2=dopen('tmp');
dir = not not rc2;
if not dir then do;
fid=fopen('tmp','i',0,'b');
lastmod=input(finfo(fid,foptname(fid,5)),NLDATM100.);
size=input(finfo(fid,foptname(fid,6)),32.);
fid=fclose(fid);
end;
else do;
dname=catx('/',dname,filename);
filename=' ';
lastmod=input(dinfo(rc2,doptname(rc2,5)),NLDATM100.);
end;
replace;
if dir;
level=level+1;
do i=1 to dnum(rc2);
filename=dread(rc2,i);
output;
end;
rc3=dclose(rc2);
run;
If it doesn't, ask your SAS administrator where the navigation path is set to by the server configuration in SAS metadata, so you can use this instead of $HOME in the first step.
Thank you very much for your help, about 24k records have appeared but I really don't know where they come from, look for one that contains '.csv' in the filename field but none appeared, so I don't know if I'm redirecting the path to where I must, how can I know if the navigation path is different from that of home?
Ask your SAS administrator(s) where they set the navigation root of the workspace server.
Look at how $HOME is defined:
%put %sysget(HOME);
It has worked changing my route, thank you very much!! One last question, how could I put the size in KB and another column in GB? because the value is returned to me in bytes
See this format that adapts itself according to the amount:
proc format;
picture kmg
0 - 1023 = [5.]
1024 - 1048575 = "009K"(mult=.0009765625)
1048576 - 1073741823 = "009M" (mult=9.5367431640625E-7)
1073741824 - high = "000.009G" (mult=9.3132257461548E-10)
;
run;
Hello everyone, I'm new to programming in SAS, I'm trying to see how much the tables and data occupy within the SAS server. I have managed to figure out how much the tables take up thanks to built-in SAS functions like dictionary.tables, from which I extract a lot of information. However, for the "Archivos" folder I would like to do the same but I think there are no functions of this type, where they give you information about the size, the last modification date etc.
In this attached image I indicate which folder within SAS I want to go through to see what the files inside occupy:
Searching the internet I found a code that goes through all the "Files" folders according to the path you indicate, the only problem is that this macro does not return the size of these files or the last modification date, I would like to have an output the same as the one I currently have but adding those 2 more fields, size (either in kb or mb/gb) and date of last modification. Here is the code, you just have to change the path.
data work.list ; length type $ 10 name $ 512 relpath $ 1024 path $ 2048 queue $ 10240 root $ 512 ; * -- initialise our queue with the root directory -- ; root = "/opt/sas/data/xxx/xxx/SASGuide/pg/" ; * -- initialise our queue with the current directory -- ; queue = "." ; k = 1 ; q_entry = scan( strip(queue), k, "|" ); do while ( not missing( q_entry ) ); * -- assign reference to the current entry -- ; if ( filename( 'ditem', catx( "/", root, q_entry ) ) ^= 0 ) then continue ; * -- reset return variables and any references -- ; call missing( name, relpath, path, type, did ); * -- assign directory reference -- ; did = dopen( 'ditem' ); if ( did = 0 ) then continue ; * -- could not open directory ... next ; do i = 1 to dnum( did ) ; * -- common reference details to both directory and files -- ; * -- get name -- ; name = dread( did, i ); * -- get relative path -- ; relpath = strip(tranwrd( catx( "/", q_entry, name ), './', '')); * -- get absolute path -- ; path = catx( "/", root, relpath ); * -- determine directory or file -- ; if ( filename( 'item', path ) ^= 0 ) then continue; * <-- could not assign a filename so next item ; ditem = dopen( 'item' ); if ( ditem > 0 ) then do; * a directory ; type = "DIR"; output ; * add directory to the output data set ; rc = dclose( ditem ); rc = filename( 'item', '' ); * -- add it to the queue -- ; call catx( "|", queue, relpath ) ; continue ; * <-- next directory ; end; * -- if we are here .. it is a file -- ; type = "FILE"; * ... derive any file properties here ... ; * -- clear the file reference -- ; rc = filename( 'item', '' ) ; output ; * add file to the output data set ; end; * -- close directory reference -- ; rc = dclose( did ) ; * -- get next directory in the queue -- ; k = k + 1 ; q_entry = scan( strip(queue), k, "|" ); end; run;
Could someone give me a hand with this or send me documentation that can help me to do what I want? I imagine that by getting a data step that adds these fields to the work.list I would have, but I don't know how to do this.
Thank you very much in advance.
@Abelp9 wrote:
.....
Searching the internet I found a code that goes through all the "Files" folders according to the path you indicate, the only problem is that this macro does not return the size of these files or the last modification date
The data step code I gave you does exactly this (determine size and last modification), so I moved this post here.
Hello good! I have been testing the code that you sent me and it works perfectly, although finally I am encountering some encoding problems, when I focus the path to a folder that has files with an encoding other than UTF-8 I get this error message :
ERROR: Some code points were not transcoded. ERROR: Some code points were not transcoded. ERROR: Some code points were not transcoded. ERROR: Some code points were not transcoded. ERROR: Some code points were not transcoded. ERROR: Some code points were not transcoded.
How can i fix this? thank you very much in advance
My code never reads a file, it only reads file metadata. So a transcoding issue could only happen with funny file/path names. Rectify that, as "funny" filenames will bite you in the behind anyway, sooner or later.
If you just want to delete stuff, why don't you log on to the server and remove files from the commandline?
i'm having troubles with the same error
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.