DATA Step, Macro, Functions and more

fileexist function in UNIX

Reply
Contributor
Posts: 65

fileexist function in UNIX

Hi, I am Using fileexist function to check if the a file is present in Unix location it is working fine, when I execute the code through eg or sas studio, but when I execute it through PC SAS it doesn't recognize the file. When I use PC SAS, I get the program path and derive the file location as in accordance with the actual unix location and set it as a macro variable using SYSLPUT. The libnames gets created perfectly with the path specified. Even if I hard code the correct path it shows the value as 0, that the file is not present I tried mutiple options 1.using filename reference Filename prgconf "&path/config.csv"; %put %sysfunc(fileexist(prgconf); 2.macro variable %put %sysfunc(fileexist(&path/config.csv); 3.direct hardcoded path %put %sysfunc(fileexist(/infra/integ/config.csv); but always the value is 0, how can I check the file presence, is there any other way. Kindly help. Thanks, Moovendhan Devaraj
PROC Star
Posts: 1,759

Re: fileexist function in UNIX

Posted in reply to DMoovendhan

It looks like your EG/Studio server is unix, and you have a different unix userid when using the server via a client and when accessing the file from a PC via samba.

Have you checked the authorisations on the file? and on the directory?

 

Wait, do you actually use /infra/integ/config.csv on the PC?

 

 

Contributor
Posts: 65

Re: fileexist function in UNIX

Yes, EG and Studio are configured to the UNIX servers... For PC sas I access it through Samba and the execution happens through, signon to remote server and rsubmit.
Super User
Super User
Posts: 7,039

Re: fileexist function in UNIX

[ Edited ]
Posted in reply to DMoovendhan

You mentioned %SYSLPUT so it sounds like you are using SAS/Connect. So make sure you know where you macro code is running.

 

If you run 

%put %sysfunc(fileexist(/infra/integ/config.csv)); 

on your PC then the answer will always be 0 unless you have a file named

\infra\integ\config.csv

on whatever disk is the current working disk for the Windows process that is running SAS.

 

Contributor
Posts: 65

Re: fileexist function in UNIX

the execution is in remote server through rsubmit after remore signon. The file is present in the remote server.
Contributor
Posts: 65

Re: fileexist function in UNIX

Posted in reply to DMoovendhan

When I execute the function file exist with in macro itrs not working, when I execute iot as a separste code it works fine

 

with in macro 

 

MPRINT(SETUP): rsubmit
NOTE: Remote submit to RMT.__7551 commencing.
MLOGIC(SETUP): %PUT
%sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibac
terial_antifungal/arw_sas_prgconfig.csv))
0
MPRINT(SETUP): ; x "pwd";
MPRINT(SETUP): endrsubmit;
NOTE: Current working directory is '/dmck1t/3rdparty/tpsandbox'.
1 x "pwd"
1 ! ;
NOTE: Remote submit to RMT.__7551 complete.

 

 

 

 

As separate code,

 

 

1 %put
1 ! %sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibact
1 ! erial_antifungal/arw_sas_prgconfig.csv));
1
NOTE: Current working directory is '/dmck1t/3rdparty/tpsandbox'.
2 x "pwd"
2 ! ;
NOTE: Remote submit to RMT.__7551 complete.

 

 

I have hardcoded the paths in in both the places and its just a copy

PROC Star
Posts: 1,322

Re: fileexist function in UNIX

Posted in reply to DMoovendhan

That's odd (i.e. doesn't make sense).  And I see you have rsubmit involved.  Can you try running both tests in a single submission?  That is, submit all of the following at once:

 

 

%macro test;
  %PUT Inside macro: >>%sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibacterial_antifungal/arw_sas_prgconfig.csv))<<;
%mend test;

%test;
%PUT outside macro: >>%sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibacterial_antifungal/arw_sas_prgconfig.csv))<<;

 

From the MLOGIC it looks like maybe you are missing a semicolon at the end of your %PUT statement in the macro?

Contributor
Posts: 65

Re: fileexist function in UNIX

Thanks For your comment Quentin, in either of the cases it worked.

But your comment helped me to think otherways and to resolve the issue.

 

My code was like this 

 

%Macro chk1;

     %if <condition> %then %do;

       Signon remote = <server> User = _prompt_ Pass_prompt_;

       rsubmit;

    %end;

%IF %sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibacterial_antifungal/arw_sas_prgconfig.csv)) %then %do;

<Statements>

%end;

%mend;

 

In this code the macro was executing in the local system and the sas codes were executing in the remote system, so during the execution fileexist was executing in the local machine and so it didn't find the file present.

 

I tackled the issue by creating a submacro after the remore login, as below, so the macro gets compiled and executed in the remote 

 

%Macro chk1;

     %if <condition> %then %do;

       Signon remote = <server> User = _prompt_ Pass_prompt_;

       rsubmit;

    %end;

%macro rtp1;

 %IF %sysfunc(fileexist(/interface/3rdparty/arp/test/bards/sandbox_development/hes/mk5592/antibacterial_antifungal/arw_sas_prgconfig.csv)) %then %do;

            <Statements>

      %end;

%mend rtp1;

  %rtp1;

%mend;

Ask a Question
Discussion stats
  • 7 replies
  • 504 views
  • 1 like
  • 4 in conversation