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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

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.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thanks a lot sir! 

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

SASKiwi
PROC Star

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.  

Shmuel
Garnet | Level 18

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;      
Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

Just  tried  but not working Shmuel,

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

Kurt_Bremser
Super User

@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.

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9
Sorry i dont know what you mean
Kurt_Bremser
Super User

@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...

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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