Help using Base SAS procedures

check for the existance of a data set or group of data sets?

Reply
Contributor
Posts: 42

check for the existance of a data set or group of data sets?

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
Super User
Posts: 19,871

Re: check for the existance of a data set or group of data sets?

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
Contributor
Posts: 42

Re: check for the existance of a data set or group of data sets?

Genius! That method works perfect, thanks so much!
Super User
Posts: 3,260

Re: check for the existance of a data set or group of data sets?

There's also the EXIST function for checking if a SAS dataset exists or not:

if EXIST('library.dataset') then......;
Contributor
Posts: 42

Re: check for the existance of a data set or group of data sets?

Thanks Kiwi, I didn't realized the "exist" function existed Smiley Happy. How convenient!
Ask a Question
Discussion stats
  • 4 replies
  • 190 views
  • 0 likes
  • 3 in conversation