Sample 26011: Reading zipped files on Windows
/******************************************************/
/* The syntax parameters for wzunzip are: */
/* */
/* specify the location of the downloaded add-on */
/* -o = overwrite existing file */
/* -c = display contents of file to screen */
/* name of zip file */
/* name of file inside of zip to be read */
/* */
/* Note the contents of the zipped file are read */
/* directly, no extraction is performed. */
/******************************************************/
filename foo pipe '"c:\program files\winzip\wzunzip.exe"
-o -c
c:\sample01584_1_data.zip
testfile.txt';
/* The zip file, sample01584_1_data.zip, is flat file created */
/* from PROC Export and SASHELP.CLASS. */
data test;
/* Use FIRSTOBS= to skip the first 8 records related to zip */
/* information, and the 9th record which contains a header */
/* record of variable names from SASHELP.CLASS. */
infile foo firstobs=10 truncover dsd;
input name :$9. sex :$1. age height weight;
run;
proc print;
run;
/* RESULTS */
Obs name sex age height weight
1 Alfred M 14 69.0 112.5
2 Alice F 13 56.5 84.0
3 Barbara F 13 65.3 98.0
4 Carol F 14 62.8 102.5
5 Henry M 14 63.5 102.5
6 James M 12 57.3 83.0
7 Jane F 12 59.8 84.5
8 Janet F 15 62.5 112.5
9 Jeffrey M 13 62.5 84.0
10 John M 12 59.0 99.5
11 Joyce F 11 51.3 50.5
12 Judy F 14 64.3 90.0
13 Louise F 12 56.3 77.0
14 Mary F 15 66.5 112.0
15 Philip M 16 72.0 150.0
16 Robert M 12 64.8 128.0
17 Ronald M 15 67.0 133.0
18 Thomas M 11 57.5 85.0
19 William M 15 66.5 112.0
Note: The following messages will be written to the SAS log because
this method is reading the zip file directly from STDERR.
Stderr output:
Searching...
/* LOG Output */
1 filename foo pipe '"c:\program files\winzip\wzunzip.exe"
2 -o -c
3 c:\sample01584_1_data.zip
4 testfile.txt';
5
6 /* The zip file, sample01584_1_data.zip, is flat file created */
7 /* from PROC Export and SASHELP.CLASS. */
8
9 data test;
10 /* Use FIRSTOBS= to skip the first 8 records related to zip */
11 /* information, and the 9th record which contains a header */
12 /* record of variable names from SASHELP.CLASS. */
13 infile foo firstobs=10 truncover dsd;
14 input name :$9. sex :$1. age height weight;
15 run;
NOTE: The infile FOO is:
Unnamed Pipe Access Device,
PROCESS="c:\program files\winzip\wzunzip.exe" -o -c
c:\sample01584_1_data.zip testfile.txt,
RECFM=V,LRECL=256
Stderr output:
Searching...
NOTE: 19 records were read from the infile FOO.
The minimum record length was 17.
The maximum record length was 21.
NOTE: The data set WORK.TEST has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.29 seconds
cpu time 0.06 seconds
16
17 proc print;
18 run;
NOTE: There were 19 observations read from the data set WORK.TEST.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.15 seconds
cpu time 0.03 seconds
If you want to run this sample with the code 'as is' on the Full Code tab, download this zipped file, sample01584_1_data.zip, to your C drive. If you download elsewhere, be sure you edit the code sample to point to the correct location of the zip file.
Download the zip file
Use the Winzip Command Line Support Add-on and a FILENAME statement to read zipped files into a SAS data set.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step Common Programming Tasks ==> Reading and Writing External Data
|
| Date Modified: | 2007-11-07 14:43:11 |
| Date Created: | 2006-01-18 16:42:11 |
Operating System and Release Information
| SAS System | Base SAS | Windows | n/a | n/a |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | n/a | n/a |
| OS/2 | n/a | n/a |