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;
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...
What is IN the zip files? A ZIP file can contain any type of file and one ZIP file can contain many files.
The files are .txt.zip. So it's just a bunch of text in them. I'm not exactly sure of all the contents
@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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.