Date: Fri, 8 Aug 2003 19:38:41 -0400
Reply-To: "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>
Subject: Re: help on fileref()/fexist()....
Content-Type: text/plain; charset="iso-8859-1"
Ben:
fileexist() requires a physical filename. When using a fileref like you are
here, you must use the fexist() function.
Having said that, it's still not going to do you a great deal of good. The
fexist() function returns a 1 ( i.e. good ) even if you've specified a
non-existent file in the filename statement when using the FTP access
method. Subsequent data steps trying to read data from the allegedly good
fileref will error with "Physical file does not exist".
You're better off using the file_number = fopen('fileref',I); function.
It'll return zero if the open was UNsuccessful. Don't forget to issue the
fclose(file_number) to close the file after a successful open.
Note that both fopen and fclose are usuable in the macro environment if you
wrap the functions with %sysfunc ( drop the quotes in the fopen function ).
Two examples below, first one is successful, note how fexist_rc = 1 in both
cases, but filenumber = 0 in the second ( i.e. non-existent file ) case.
37 filename ftpscr ftp 'ftp_triad.ksh' user='xxxx' pass=XXXXXXXX
38 host='xxxx';
39
40 data a;
41 fexist_rc = fexist('ftpscr');
42 put fexist_rc=;
43 filenumber = fopen('ftpscr','I');
44 put filenumber=;
45 if filenumber then
46 rc = fclose(filenumber);
47 run;
fexist_rc=1
NOTE: 220 xxxx FTP server (SunOS 5.8) ready.
NOTE: User xxxx has connected to FTP server on Host xxxx
filenumber=1
NOTE: The data set WORK.A has 1 observations and 3 variables.
NOTE: DATA statement used:
real time 0.13 seconds
cpu time 0.01 seconds
NOTE: Remote submit to T_880 complete.
12 rsubmit;
NOTE: Remote submit to T_880 commencing.
48 filename ftpscr ftp 'ftp_triad.ksh' user='xxxx' pass=XXXXXXXX
49 host='xxxx';
50
51 data a;
52 fexist_rc = fexist('ftpscr');
53 put fexist_rc=;
54 filenumber = fopen('ftpscr','I');
55 put filenumber=;
56 if filenumber then
57 rc = fclose(filenumber);
58 run;
fexist_rc=1
NOTE: 220 xxxx FTP server (SunOS 5.8) ready.
filenumber=0
NOTE: The data set WORK.A has 1 observations and 3 variables.
NOTE: DATA statement used:
real time 0.03 seconds
cpu time 0.02 seconds
-----Original Message-----
From: ben [mailto:benpub7@YAHOO.COM]
Sent: August 8, 2003 4:50 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: help on fileref()/fexist()....
On Fri, 8 Aug 2003 10:23:24 -0400, Charles Patridge
<charles_s_patridge@PRODIGY.NET> wrote:
>Ben,
>
>You need to show us your code and a little about your
environment - such as
>local environment characteristics and your remote
environment.
>
>Plus, how are you trying to access these remote files with
fexist function?
>
>A little shown code could/would be extremely helpful to
assist you.
>
>HTH,
>Charles Patridge
here is code, thanks.
filename dds2 ftp "right.one"
cd="" user='...' pass='....'
host='www.some.com' recfm=v prompt;
****exist;
filename dds1 ftp "wrong.one"
cd="" user='...' pass='....'
host='www.some.com' recfm=v prompt;
****not exist;
223 data x;
224 x1=fileref('dds2');
225 x1_1=fileexist('dds2');
226 x2=fileref('dds3');
227 x2_1=fileexist('dds3');
228 *x1=fileref(dds);
229 put x1= x2= x1_1= x2_1=;
230 run;
x1=0 x2=0 x1_1=0 x2_1=0
NOTE: The data set WORK.X has 1 observations and 4
variables.
NOTE: DATA statement used:
real time 0.01 seconds
cpu time 0.01 seconds