Skip to content
9to5sas
  • Index
  • Glossary
Facebook Twitter Instagram Email RSS

  • Start Here
  • Base SAS
  • Advanced SASExpand
    • SAS Macros
    • PROC SQL
  • SAS/STATSExpand
    • SAS Analytics
    • Statistics
  • SAS Programs
9to5sas

9to5sas » SAS PROGRAMS » How to read zip files in SAS?

How to read zip files in SAS?

BySubhro Posted onAugust 28, 2021August 29, 2021 Last Updated:August 29, 2021
0 Comments

You can read zip files in SAS without having to decompress the file first. SAS will first unzip the file and then input the data set through the zip engine.

You can read zip files in SAS without having to decompress the file first. SAS will first unzip the file and then input the data set through the zip engine.

Let’s say that we have some CSV files stored in a ZIP folder. We want SAS to extract these files and use them as data sets.

As an example, we created a ZIP file with three files :

csv_inputs.zip
  |__ class.csv
  |__ cars.csv
  |__ prdsale.csv

Read zip files in SAS using Proc Infile

filename inzip ZIP '/home/9to5sas/inputs/csv_inputs.zip';
data newdata;
infile inzip(class.csv) firstobs=2 dlm=",";
input Name $ Sex $ Age Height Weight;
run;

Read zip files in SAS using Proc Import

To read zip files in SAS using Proc Import does require an extra step. Proc Import cannot access the content directly while it’s in the archive.

So, the additional step is to copy the file to another location like in the temporary work location and then extracting it from the ZIP file.

You can even read xlsx file using this method.

xlsx_inputs.zip
  |__ class.xlsx
  |__ cars.xlsx
  |__ prdsale.xlsx
filename inzip ZIP '/home/9to5sas/inputs/xlsx_inputs.zip';

/* copy the file to working directory and then load it */
filename readExcel "%sysfunc(getoption(work))/class.xlsx" ;

data _null_;
infile inzip(class.xlsx) 
lrecl=256 recfm=F length=length eof=eof unbuf;
file readExcel lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;

proc import datafile=readExcel out=label dbms=xlsx replace;
getnames=yes;
run;

We hoped this article helped you to read zip files in SAS. Moreover, if you have any other suggestions, suggest them in the comment section. We would really take those lists in our further blog post.

Thanks for reading!

You may also want to read How to zip and Unzip files in SAS?

Every week we'll send you SAS tips and in-depth tutorials

JOIN OUR COMMUNITY OF SAS Programmers!

Check your inbox or spam folder to confirm your subscription.

Post Tags: #import zip files in sas#read zip files in sas
Subhro

Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.

Facebook Twitter Linkedin

Post navigation

Previous Previous
How to zip and Unzip files using SAS?
NextContinue
Creating a custom sort order in SAS

SAS Tips in your inbox

Subscribe to 9to5sas for timely SAS tips and news delivered each month.
Learn about the latest articles, and code samples to keep your SAS skills fresh!

Your subscription is successful!

Recent Posts

  • Concatenate strings in SAS: The CAT Functions Demystified
  • 5 Techniques for Quickly Removing Leading Zeros in SAS
  • Troubleshoot Your Proc SQL Code Like a Pro with These 7 Automatic Macro Variables
  • 7 PROC SQL Options You Should Use to Debug Queries
  • How To Use The SAS Proc SQL Order By Statement?
9to5sas
  • Privacy Policy
  • Disclaimer
  • About
  • Contact
Facebook Twitter Instagram RSS Email Pinterest

Copyright © 2023 9TO5SAS, All rights reserved.

Scroll to top
  • 9to5sas Blueprint
  • About
  • About
  • Acceptable use policy
  • calculator
  • Confirm email
  • Contact
  • Contact
  • Cookie Policy
  • DISCLAIMER
  • Getting Started with SAS
  • Glossary
  • Index
  • Post #13801
  • Privacy Policy
  • Privacy policy
  • SAS Programs
  • Styles
  • Subscription confirmed
  • Terms and conditions
  • Thank You