DATA Step, Macro, Functions and more

Trouble reading a DBF file from a zip file using SASZIPAM

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Trouble reading a DBF file from a zip file using SASZIPAM

Hi all,

I am having trouble importing data from a zipped DBF file in SAS 9.3 (using EG 5.1).

As-is situation

Right now, I have to manually unzip the weekly updates and import the DBF files using proc import with DBMS set to 'DBF'.

To-be situation

Read and import the DBF files directly from the zipfiles.

Approach

Declare the zipfile using the filename statement and SASZIPAM option and import the DBF file using a datastep, as described here.

Problem

There are 2 problems, either of which would be a solution if solved:

  1. It seems impossible to import a DBF file to SAS by use of a datastep (Googling suggests to convert the DBF file to a CSV file, which is not an option here).
  2. It seems impossible to use a PROC IMPORT using the filename that refers to the zipped DBF, declared with the SASZIPAM option.

Any ideas on how to best approach this?

Cheers,

Kirvis


Accepted Solutions
Solution
‎04-28-2014 06:58 AM
New Contributor
Posts: 3

Re: Trouble reading a DBF file from a zip file using SASZIPAM

Thanks again for your reply.

I have eventually managed to activate 7-zip using the following code:

data _null_ ;

     unzipcmd=     ' "C:\Program Files\7-zip\7z.exe" ' ;

     zipfile=           'C:\MyDocuments\zipfile.zip' ;

     whereto=        'C:\MyDocuments\target_dir\' ; 

     cmd=unzipcmd || ' x ' || zipfile || ' o-' || whereto ;

putlog "NOTE-Files are extracted" cmd ;

call system(cmd);

run;

I realise I can make this more flexible using macro variables and things like that, but for now, this does work.

Thanks!

View solution in original post


All Replies
Valued Guide
Posts: 3,208

Re: Trouble reading a DBF file from a zip file using SASZIPAM

can you upgrade to sas 9.4?  New features Zip filename.

With 9.3 you could use ODS Document for zipping/unzipping

import usage, why not use proc dbf?

SAS/ACCESS(R) 9.4 Interface to PC Files: Reference, Second Edition (proc dbf)

SAS/ACCESS(R) 9.3 Interface to PC Files: Reference (proc dbf)

---->-- ja karman --<-----
New Contributor
Posts: 3

Re: Trouble reading a DBF file from a zip file using SASZIPAM

Hi Jaap,

Thanks for your reply. To comment on it:

  • updating to 9.4 is not an option unfortunately
  • I tried using proc dbf, but that means I have to unzip the files first, which is exactly what I would like to prevent using the SASZIPAM option in the filename statement. It seems impossble to use a proc statement after defining the filename of the zipfile, I have to use a data step to import the data

Unzipping the files on the server and importing them would be a third option, but I have not managed to figure that out either.

Thanks

Valued Guide
Posts: 3,208

Re: Trouble reading a DBF file from a zip file using SASZIPAM

Ok, you will need always a two-step process approach   1/ the unzip 2/ dbf to SAS

I Checked the ODS package approach it will allow you to zip but I cannot find unzip. That is a weird approach at SAS as a lot is related to ZIP-functionality although not always made visible.

The two steps can be done in your case by

-unzip step (possible containing many files) using a XCMD (pipe systask processing) . That should work with SAS 9.3 at SAS/base windows  (SASZIPAM is windows only)

- the conversion step.

you can specify needed checkpoints in your process as for existence of the wanted filenames.  

Still one program or EGP-flow with several steps you can run.     

---->-- ja karman --<-----
Solution
‎04-28-2014 06:58 AM
New Contributor
Posts: 3

Re: Trouble reading a DBF file from a zip file using SASZIPAM

Thanks again for your reply.

I have eventually managed to activate 7-zip using the following code:

data _null_ ;

     unzipcmd=     ' "C:\Program Files\7-zip\7z.exe" ' ;

     zipfile=           'C:\MyDocuments\zipfile.zip' ;

     whereto=        'C:\MyDocuments\target_dir\' ; 

     cmd=unzipcmd || ' x ' || zipfile || ' o-' || whereto ;

putlog "NOTE-Files are extracted" cmd ;

call system(cmd);

run;

I realise I can make this more flexible using macro variables and things like that, but for now, this does work.

Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 609 views
  • 3 likes
  • 2 in conversation