The filename statement is very flexible. Here are a few examples that
show
some of that flexibility. For more info see
http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000210819.htm
-
and remember to check out the operating system specific functionality
whenever that option is available - sometimes it tells you a lot,
sometimes
not much.
Windows -
http://support.sas.com/onlinedoc/913/getDoc/en/hostwin.hlp/win-func-f...
.htm
UNIX -
http://support.sas.com/onlinedoc/913/getDoc/en/hostunx.hlp/a000195127...
z/OS -
http://support.sas.com/onlinedoc/913/getDoc/en/hosto390.hlp/a00020177...
Here are some examples of different uses of the filename statement.
Code
* The following two filename statements are equivalent, since DISK is
the
default filename engine ;
filename out disk 'c:\test.txt' ;
filename out 'c:\test.txt' ;
data _null_ ;
file out ;
set sashelp.class ;
put _all_ ;
run ;
* dummy file which is a "black hole" ;
filename rubbish dummy ;
data _null_ ;
file rubbish ;
set sashelp.class ;
put _all_ ;
run ;
* useful to allocate a temporary file ;
filename wrk temp ;
data _null_ ;
file wrk ;
put 'test' ;
run ;
data _null_ ;
infile wrk ;
input ;
put _infile_ ;
run ;
* read output of a program from a pipe ;
filename cmd pipe 'dir c:' ;
data _null_ ;
infile cmd ;
input ;
put _infile_ ;
run ;
* Send output directly to default printer ;
filename p printer ;
data _null_ ;
file p ;
set sashelp.class ;
put _all_ ;
run ;
* Can read & write to catalog members of various types ;
filename cat catalog 'work.test.my.output' ;
data _null_ ;
file cat ;
set sashelp.class ;
put _all_ ;
run ;
* read & write to clipboard ;
filename clip clipbrd ;
data _null_ ;
file clip ;
put 'Some text to paste into somewhere.' ;
run ;
* I pasted the contents of clipboard into the following comment -
note: it
also put in a carriage return ;
/*Some text to paste into somewhere.
*/
* Send emails ;
FILENAME report EMAIL 'p...@woodstreet.org.uk' subject='test mail'
attach='c:\test.txt' ;
data _null_ ;
file report ;
put 'Hi. Here is my test email' ;
run ;
* read or write to FTP sites ;
filename host ftp 'README.txt' host='ftp.sas.com' cd='/techsup/
download'
user='anonymous' debug ;
data _null_ ;
infile host ;
input ;
put _infile_ ;
run ;
* read from a web site ;
filename x url 'http://www.sas.com' ;
data _null_ ;
infile x ;
input ;
put _infile_ ;
run ;
* access TCP sockets - too specific for a general working
example ... ;
filename local socket ':5000' server reconn=3;
* access a file at a web site ;
filename foo sasxbamw
'http://www.mycompany.com/production/files/rawFile.txt' user='wong'
pass='jd75ld';