BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Abelp9
Quartz | Level 8

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 .

 

sas.PNG

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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

12 REPLIES 12
Kurt_Bremser
Super User

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.

Abelp9
Quartz | Level 8

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?

Abelp9
Quartz | Level 8

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

Kurt_Bremser
Super User

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;
Abelp9
Quartz | Level 8

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:

foro.PNG

 

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.

 

Kurt_Bremser
Super User

@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.

Abelp9
Quartz | Level 8

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

Kurt_Bremser
Super User

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.

Abelp9
Quartz | Level 8
and there is no way to read the metadata files that have tildes or weird symbols? I just want to get rid of that garbage
danzsas
Calcite | Level 5

i'm having troubles with the same error

SAS Innovate 2025: Register Now

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!

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 12 replies
  • 3361 views
  • 5 likes
  • 3 in conversation