BookmarkSubscribeRSS Feed
C_Myers2211
Fluorite | Level 6

I have a bunch of zip files on a SAS Server that I want to move into a SAS Library. I'm not sure of the code for how to do this.

 

I saw code for exporting a csv file to a library and I tried with the zip file but I'm not sure what dbms= should be.

 

proc import out=mylib.mydata datafile='/folders/myfolders/test.csv' dbms=CSV replace; 
run;
4 REPLIES 4
ChrisHemedinger
Community Manager

A SAS library is mechanism to abstract the way data appears in SAS from the way it's actually stored. Often a SAS library is just an alias to a file folder, but it can also be a database, a series of aggregated folders, or other storage mediums.

 

So you can't really store the ZIP file as-is in the library, though you could place it in the same folder to which a SAS libname is mapped...if that's the style of library (BASE engine) that you're using. The SAS pathname() function can help you find the actual library path in that case.

 

If you want to store the actual contents of the ZIP file as data in the library (example: you have one or more CSV files in the ZIP and you want them to be SAS data sets in the library), then you would use SAS code to reference them (FILENAME ZIP) and use DATA step or PROC IMPORT to create the data in the target library. I don't think that's what you're asking though...

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Tom
Super User Tom
Super User

What is IN the zip files?  A ZIP file can contain any type of file and one ZIP file can contain many files.

C_Myers2211
Fluorite | Level 6

The files are .txt.zip. So it's just a bunch of text in them. I'm not exactly sure of all the contents

Tom
Super User Tom
Super User

@C_Myers2211 wrote:

The files are .txt.zip. So it's just a bunch of text in them. I'm not exactly sure of all the contents


In that case there is no need to "store" the ZIP file in a library.

You might want to create a SAS library to store the SAS datasets you ultimately generate form the TXT files so that the next time you want to reference that data you don't have to go through the process of converting the TXT into dataset(s).

 

You can use a fileref to point to the ZIP file and extract the individual members (files) from it.  You can point a fileref at the ZIP and treat it like a directory.

filename myzip zip 'phystical_filename.zip' ;
data want;
  infile myzip('individual_filename.txt') dsd truncover ;
  input var1-var5;
run;

Or you could make a fileref that points to an individual file.

filename myfile zip 'phystical_filename.zip' member='individual_filename.txt';

Or you can skip that and just use the ZIP engine with the INFILE statement directly.

data want;
  infile 'physical_filename.zip' zip member='individual_filename.txt' dsd truncover ;
  input var1-var5;
run;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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