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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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-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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 13365 views
  • 1 like
  • 3 in conversation