BookmarkSubscribeRSS Feed
KevinC_
Fluorite | Level 6

Hello Everyone,

I am trying to read an Excel file that has been zipped.  The Excel file name is new_file.xlsx.  It has been zipped and sits in c:\docs\new_file.zip.

How do I read this file without manually unzipping it first?  I have tried Proc Import and x command.  Here is my attempt using x command:

"cd C:\Program Files\7-Zip\";

'7z.exe e -o C:\docs\OUTPUT.xlsx C:\docs\new_file.zip';

When I run this code I don't get any errors.  It does not seem to produce any output either.

Any suggestions would be greatly appreciated.

Thank you! 

4 REPLIES 4
andreas_lds
Jade | Level 19

With SAS 9.4 you can use the filename statement to access a zip file. Have a look at FILENAME Statement, ZIP Access Method :: SAS(R) 9.4 Statements: Reference, Third Edition.

Kurt_Bremser
Super User

To get the output of external commands into the log, use this construct:

filename oscmd pipe "your_command 2>&1";* the 2>&1 redirects stderr output to stdout;

data _null_;

infile oscmd;

input;

put _infile_;

run;

You won't be able to do it all in one step, though; the ZIP file access method can only read text from zipped files. So you will have to unzip the file first and then use one of the excel access methods (probably libname xlsx) to read from the .xlsx.

jakarman
Barite | Level 11

When it is only an excel file xlsx type being zipped it makes no sense.  The xlsx file is an zip-file having xml files and references inside it. You can open an xlsx file with 7zip yourself yourself.

---->-- ja karman --<-----
ChrisHemedinger
Community Manager

As Andreas pointed out, FILENAME ZIP can be used to extract the file, and then you can read the result with PROC IMPORT.  See examples of using FILENAME ZIP in this blog post.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2228 views
  • 0 likes
  • 5 in conversation