BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

FILENAME has optional arguments such as TEMP, ZIP, URL, etc. Can one use two or more arguments simultaneously? For example, can FILENAME refer a zip file on the Internet as follows?

filename myfile zip url "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors_TXT.zip";

Or can FILENAME be a temporary zip file? Probably not as the SAS document says ZIP must be a ufs file and it seems TEMP is not.

filename myfile temp zip;

I tried several arguments simultaneously but didn't work. Thanks for help.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You cannot ask SAS to run two different filename engines in the same filename.

Copy the file to your local machine.  Then you can use the ZIP engine to extract something from the file.

filename webfile url
 'https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors_CSV.zip'
  recfm=f lrecl=512
;
filename middle temp   recfm=f lrecl=512;
data _null_;
  rc=fcopy('webfile','middle');
  if rc then do;
    length msg $ 384;
    msg=sysmsg();
    put rc= msg=;
  end;
run;
filename text zip "%sysfunc(pathname(middle))" member='*' ;

Now you can read the text out of the zip file:

data want ;
  infile text truncover firstobs=5 dsd ;
  input var1-var5 ;
run;

View solution in original post

3 REPLIES 3
Norman21
Lapis Lazuli | Level 10

You can specify one file within the zip, if that is what you need:

 

filename foo ZIP 'U:\directory1\testzip.zip' member="test1.txt" ;

Example 1 in https://documentation.sas.com/?docsetId=lestmtsglobal&docsetTarget=n1dn0f61yfyzton1l2ngsa1clllr.htm&...

Norman.
SAS 9.4 (TS1M6) X64_10PRO WIN 10.0.17763 Workstation

Junyong
Pyrite | Level 9

Thanks, but suppose that the zip file is now on the Internet as follows.

https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors_CSV.zip

Can I feed one member of this url as the FILENAME?

Tom
Super User Tom
Super User

You cannot ask SAS to run two different filename engines in the same filename.

Copy the file to your local machine.  Then you can use the ZIP engine to extract something from the file.

filename webfile url
 'https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/ftp/F-F_Research_Data_Factors_CSV.zip'
  recfm=f lrecl=512
;
filename middle temp   recfm=f lrecl=512;
data _null_;
  rc=fcopy('webfile','middle');
  if rc then do;
    length msg $ 384;
    msg=sysmsg();
    put rc= msg=;
  end;
run;
filename text zip "%sysfunc(pathname(middle))" member='*' ;

Now you can read the text out of the zip file:

data want ;
  infile text truncover firstobs=5 dsd ;
  input var1-var5 ;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 503 views
  • 0 likes
  • 3 in conversation