BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kirvis
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
kirvis
Calcite | Level 5

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

4 REPLIES 4
jakarman
Barite | Level 11

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 --<-----
kirvis
Calcite | Level 5

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

jakarman
Barite | Level 11

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 --<-----
kirvis
Calcite | Level 5

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!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2316 views
  • 3 likes
  • 2 in conversation