SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
munitech4u
Quartz | Level 8

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

3 REPLIES 3
ChrisHemedinger
Community Manager

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;
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
jklaverstijn
Rhodochrosite | Level 12

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.

 

 

 

munitech4u
Quartz | Level 8

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

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 15162 views
  • 1 like
  • 3 in conversation