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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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

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
  • 819 views
  • 0 likes
  • 3 in conversation