BookmarkSubscribeRSS Feed
SASguyCO
Calcite | Level 5
I'm curious, is there a way to basically evaluate an "if" statement on whether a certain data set or group of data sets exist and if so run one process and if not, then a different process.

In other words:

%macro exists;
%if libname.dset_201104 "exists" %then %do;
data;
set;
code code code;
run;
%end;

%else %do;
data;
set;
code code code;
run;
%end;
%mend;
%exists
4 REPLIES 4
Reeza
Super User
I don't know if you do can do it in one if statement but you can use the open function to check if the dataset exists.

see open function, page 2 of the following paper.

http://www2.sas.com/proceedings/sugi26/p095-26.pdf
SASguyCO
Calcite | Level 5
Genius! That method works perfect, thanks so much!
SASKiwi
PROC Star
There's also the EXIST function for checking if a SAS dataset exists or not:

if EXIST('library.dataset') then......;
SASguyCO
Calcite | Level 5
Thanks Kiwi, I didn't realized the "exist" function existed :). How convenient!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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
  • 4 replies
  • 2972 views
  • 0 likes
  • 3 in conversation