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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 933 views
  • 0 likes
  • 3 in conversation