- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to import the csv data in zipped file using:
filename foo ZIP '/applocation/kg/label_categories.csv.zip' member="label_categories.csv" ;
proc import datafile=foo out=label dbms=csv replace; getnames=yes;run;
But the dataset contains only 1 variable with 1 length.
I know, I can read the data using: input statement. But that requires me to specify manually input for all variables, which can be tiresome a job while importing lot of files.
How can I get all the data similar to proc import, without using the input statement?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this: use DATA step to "copy" the file out of the ZIP first, then import it. I describe this in a blog post about FILENAME ZIP.
Your code might look like:
filename inzip ZIP '/applocation/kg/label_categories.csv.zip'
filename csv "%sysfunc(getoption(work))/label_categories.csv" ;
data _null_;
/* using member syntax here */
infile inzip(label_categories.csv)
lrecl=256 recfm=F length=length eof=eof unbuf;
file csv lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
proc import datafile=csv out=label dbms=csv replace; getnames=yes;run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this: use DATA step to "copy" the file out of the ZIP first, then import it. I describe this in a blog post about FILENAME ZIP.
Your code might look like:
filename inzip ZIP '/applocation/kg/label_categories.csv.zip'
filename csv "%sysfunc(getoption(work))/label_categories.csv" ;
data _null_;
/* using member syntax here */
infile inzip(label_categories.csv)
lrecl=256 recfm=F length=length eof=eof unbuf;
file csv lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
proc import datafile=csv out=label dbms=csv replace; getnames=yes;run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This makes me curious to find out what the input file looks like from the SAS perspective.
Could you execute this piece of code and share the results?
filename foo ZIP '/applocation/kg/label_categories.csv.zip' member="label_categories.csv" ;
data _null_;
infile foo obs=10;
input;
put _infile_;
run;
This dumps a piec of your unzipped file to the log. That may help understand the behaviour of proc import.
Regards,
- Jan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
here is the log:
label_id,category
1,
2,game-type
3,game- themes
4,game-Style
5,game-time
6,game-things
7,game-Finding fault
8,game-stress reliever
9,game-pet
NOTE: 10 records were read from the infile FOO.
The minimum record length was 2.
The maximum record length was 22.
but the output dataset contains this:
Var1
1
2
3
4
5