BookmarkSubscribeRSS Feed
Lost_Gary
Quartz | Level 8

I am trying to use SAS to grab information from a folder including that contains a series of recordings.  These recordings are in several different formats so Windows Explorer cannot even provide a duration of the recordings in most cases.  But I have figured out (I think) that I can take the file size and determine a length of each recording (or at least an estimate).  

 

So, what I have is the formula of:

File_Duration = File_Size * 0.00000000524111952

 

Which appears something like this:

 

File_SizeFile_DurationHow Do I Get?
122,1060.00063997210:00:49
4,019,2520.02106538010:30:03
68,5570.00035931540:00:31

 

So, What I am looking for is the actual duration in Hours, Minutes & Seconds.  I can't seem to figure out a format to convert this decimal to a duration.  But added all of this detail as I recognize that I may being going about this in the least efficient manner.  

 

Any Assistance is appreciated.

Thanks.  

 

6 REPLIES 6
andreas_lds
Jade | Level 19

A SAS-time value is the number of seconds since midnight. I can't see any logic, that would transfer File_Duration to the shown time.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

To be honest i don't think thats going to work.  There are lots of factors which will impact file size, type of movie, soundtrack, subtitles, format of file etc.  What I would suggest is you use a tool appropriate to the task to get the information, for instance:
https://unix.stackexchange.com/questions/170961/get-total-duration-of-video-files-in-a-directory

 

FreelanceReinh
Jade | Level 19

Hi @Lost_Gary,

 

I'm also skeptical about your "universal" conversion factor given that the "recordings are in several different formats."

 

That said, I guess your File_Duration values are measured in days (like times are in Excel). So, multiplying by 86400 will convert them to SAS time values:

data have;
input File_Size :comma. File_Duration;
cards;
122,106 0.0006399721
4,019,252 0.0210653801
68,557 0.0003593154
;

data want;
set have;
dur=file_duration*86400;
dur2=file_size*4.52832726528E-4; /* alternative formula */
format file_size comma10. file_duration best12. dur dur2 time8.;
run;

proc print data=want noobs;
run;

Result:

                    File_
File_Size        Duration         dur        dur2

  122,106    0.0006399721     0:00:55     0:00:55
4,019,252    0.0210653801     0:30:20     0:30:20
   68,557    0.0003593154     0:00:31     0:00:31

Note that I have included an alternative formula (based directly on File_Size) using your conversion factor times 86400 -- just for comparison (dur, dur2).

Lost_Gary
Quartz | Level 8

OK, I might be starting to accept that all of you might be right, and that this cannot be done.  So, is there a way for me to pull the length (actual recording time) from the Windows Explorer screen and then perhaps I can use this estimated process for those that do not have a published 'Length' within windows.  


I have tried various versions of my code below to capture the recording length, but I can't figure it out.  Your suggestions are appreciated.  

 

thanks!

 

filename DIR pipe "dir  ""C\my path"" /s/q/";

Data files;

infield dir pad;

input x $256.;

length PAT filename $256;

retain path;

if index(x,'Directory of') then PATH=substr(x,14);

else if char(x,3)-'/' and not index(x,'<DIR>') then do;

TOPDIR = cats('\',scan(path,1,'\',scan(path,2,'\'),scan(path,3,'\'));

filename =substr(x,63);

size = input(scan(x,4,' '),?? comma20.);

 

/* what do I put here to grab the recording length ????*/

 

output;

end;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

It can be done, but just not by using file size.  File size is a measure of bits on the physical drive, if you have a compressed format like mp3 and an uncompressed format like flac, then the duration will be the same, however the file size will be vastly difference.  This is why its not a good idea to use file size to derive length.  Use something which is designed to open the specific file, and play it, that program would be best placed to tell you lengths.

FreelanceReinh
Jade | Level 19

@Lost_Gary wrote:

filename DIR pipe "dir  ""C\my path"" /s/q/";

(...)

/* what do I put here to grab the recording length ????*/

 


I think the DOS command DIR is insufficient to retrieve extended file properties such as recording length. I've just tried to get these using relatively simple commands of Windows PowerShell (which I rarely use), but to no avail: recording length was not among the items displayed. A quick web search revealed that maybe more advanced PowerShell scripts could do the trick: https://www.powershellmagazine.com/2015/04/13/pstip-use-shell-application-to-display-extended-file-a.... But it's not clear to me if these "extended file attributes" will include recording length and I'm not familiar with such advanced PowerShell scripts anyway.

 

I'm pretty sure that either PowerShell or other software (as mentioned by RW9) can retrieve this information into a text file or pipe (which could then be read with SAS after SAS had triggered the retrieval process). For one of my projects I managed to have SAS read information from the screen (of another software) by means of a C++ script which only read the pixel colors. So, it is possible to get this information with SAS, but it might be difficult.

 

Sorry that I can't be of more help.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 886 views
  • 1 like
  • 4 in conversation