BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Hi,

Can anyone suggest how to exit from program in case file does not exit. I have some other include statement, based on file existance, I need to proceed to next program call. 

filename ip_file '&ip_folder.\&file.';
%if (%sysfunc(fexist(ip_file)) eq 0) %then %do;
%put ERROR: Physical file does not exist ==> &ip_folder.\&file. ;
%end;

%include "someother program/abcd.sas";

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

This

filename ip_file '&ip_folder.\&file.';

will fail because macro triggers do not resolve within single quotes.

You can use the FILEEXIST Function with the physical filename, so you can omit the FILENAME anyway. And you can test for existence, run the include, and put the message otherwise:

%if %sysfunc(fileexist(&ip_folder.\&file.)) %then %do;
  %include "someother program/abcd.sas";
%end;
%else %do;
  %put ERROR: Physical file does not exist ==> &ip_folder.\&file. ;
%end;

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

This

filename ip_file '&ip_folder.\&file.';

will fail because macro triggers do not resolve within single quotes.

You can use the FILEEXIST Function with the physical filename, so you can omit the FILENAME anyway. And you can test for existence, run the include, and put the message otherwise:

%if %sysfunc(fileexist(&ip_folder.\&file.)) %then %do;
  %include "someother program/abcd.sas";
%end;
%else %do;
  %put ERROR: Physical file does not exist ==> &ip_folder.\&file. ;
%end;

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 564 views
  • 1 like
  • 2 in conversation