Help using Base SAS procedures

Get the File Attributes (example: Last Updated Date) from a zip file downloaded from Web

Reply
Occasional Contributor
Posts: 9

Get the File Attributes (example: Last Updated Date) from a zip file downloaded from Web

Hi All,

I am trying to do the following

- Download a Zip File from Web. I have done this using FILENAME URL - Working Fine

- Unzip the File and get all the member data. I have done this using FILENAME ZIP, DOPEN, DREAD and FOPEN in a DATA Step - Working Fine.

- Get the Last Updated TimeStamp of every member in the ZIP File. - This is the one I need help.

- When I tried to get the File Attributes (using FOPEN, FINFO) on the unzipped file, I get current date as I have created the file during the unzip process.

- When I tried to get the File Attributes (using FOPEN, FINFO) on the zip file immediately after download, File Identifier comes as ZERO.

Hope this makes.

Any help is appreciated.

Selva

Super User
Posts: 6,928

Re: Get the File Attributes (example: Last Updated Date) from a zip file downloaded from Web

Once you have downloaded the zip file (say as foo.zip), you can use unzip -l foo to list the contents of the zip file:

Archive:  foo.zip

  Length     Date   Time    Name

--------    ----   ----    ----

       29  09-10-13 08:32   test.dat

       37  03-04-14 13:04   xxx.lst

    72949  11-14-12 14:39   wagner.log

--------                   -------

    73015                   3 files


You can use a construct like this:


filename oscmd pipe "unzip -l foo"

data fileinfo;

infile oscmd truncover end=last;

format file_name $50. file_date date9. file_time time5.;

input;

if _n_ > 3 and not last and substr(_infile_,2,8) ne '--------';

file_date = input(substr(_infile_,12,8),mmddyy8.);

file_time = input(substr(_infile_,21,5),time5.);

file_name = substr(_infile_,29);

run;


unzip is a standard tool on UNIX systems.


---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 1 reply
  • 291 views
  • 0 likes
  • 2 in conversation