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;

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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