Help using Base SAS procedures

checking for file existence

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 464
Accepted Solution

checking for file existence

hello people,

the macro below  does not recognize "myinput1" and it only  throws an output :"The file myinput1 does not exist"

why? How can  fix this?  please anyone. Thx

 

filename myinput1 ftp " 'XYZ.C.M.DATA.XYZZ.G0049V00' " user=** pass=***   host="xyz.com";
                                                    
%let testfile = myinput1;


%macro findit;                                
  %if %sysfunc(fileexist(&testfile)) %then %do;
  %put good;                                       
  %end;                                         
  %else %put The file &testfile does not exist. ;
%mend;                                    
   
%findit;


Accepted Solutions
Solution
‎10-08-2017 05:57 PM
Super User
Posts: 10,239

Re: checking for file existence

Read the documentation for fileexist():

 

Argument

file-name

is a character constant, variable, or expression that specifies a fully qualified physical filename of the external file in the operating environment.

 

You can't use a fileref.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
‎10-08-2017 05:57 PM
Super User
Posts: 10,239

Re: checking for file existence

Read the documentation for fileexist():

 

Argument

file-name

is a character constant, variable, or expression that specifies a fully qualified physical filename of the external file in the operating environment.

 

You can't use a fileref.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Super Contributor
Posts: 464

Re: checking for file existence

Posted in reply to KurtBremser

thanks a lot sir! 

So there is no way  I can check for existence of file in the mainframe host?

Super User
Posts: 3,918

Re: checking for file existence

You can only use FILEEXIST to check for the existence of a file that is available locally to SAS, not remotely via an FTP link. You would actually have to try to read the file via FTP to confirm it exists or alternatively a "directory list" - not sure how to do this on a mainframe via FTP.  

Trusted Advisor
Posts: 1,837

Re: checking for file existence

I'm not sure it will help because you use ftp engine, but you may try:

%macro findit;                                 
  %let fid=%sysfunc(fopen(testfile));
  %if %eval(&fid) > 0  %then %do;
        %put good;                                        
  %end;                                          
  %else %put Cannot open the file &testfile  ;
%mend;      
Super Contributor
Super Contributor
Posts: 464

Re: checking for file existence

Just  tried  but not working Shmuel,

Anyway so  I guess  this is not doable then. Thanks for your  help  guys

Super User
Posts: 10,239

Re: checking for file existence


Tal wrote:

thanks a lot sir! 

So there is no way  I can check for existence of file in the mainframe host?


Run a directory listing (filename ftp can do this), and check the output.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Super Contributor
Posts: 464

Re: checking for file existence

Sorry i dont know what you mean
Super User
Posts: 10,239

Re: checking for file existence

[ Edited ]

Tal wrote:
Sorry i dont know what you mean

Once again, I have to direct you to the SAS documentation:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000178980.htm#a000...

The first example shows how ro retrieve a directory listing from a remote ftp server.

While reading this infile, you can check the input line (_infile_) for the filename with the index() function.

 

Note that I referenced a 9.2 page, as the 9.4 online documentation seems to be mis-organized at the moment.

 

Edit: Link for the 9.4 documentation of the FILENAME statement, FTP method:

http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=lestmtsglobal&docsetTarget...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 486 views
  • 3 likes
  • 4 in conversation