Table of Contents
SAS (Statistical Analysis System) is a software suite commonly used for statistical analysis, data management, and predictive modeling. With its extensive library of statistical procedures and powerful data manipulation capabilities, SAS is a popular tool for handling large datasets in various industries.
To determine if a dataset exists in SAS, one can use the PROC CONTENTS procedure. This procedure provides a detailed description of the data in a SAS dataset, including the names and attributes of variables, the number of observations, and the data type.
For example, if we have a dataset named “sales_data” in SAS, we can use the PROC CONTENTS procedure to check its existence by typing the following code in the SAS program editor:
PROC CONTENTS DATA=sales_data;
RUN;
If the dataset “sales_data” exists in SAS, the procedure will display its content and characteristics. Otherwise, it will return an error message indicating that the dataset does not exist.
In conclusion, the PROC CONTENTS procedure in SAS can be used to verify the existence of a dataset, providing a formal and efficient way to manage and analyze data within the software.
Check if Dataset Exists in SAS (With Example)
You can use the following macro in SAS to quickly check if a dataset exists:
%macro check_exists(data);
%if%sysfunc(exist(&data.)) %then%do;
%put Dataset Exists;
%end;
%else%do;
%put Dataset Does Not Exist;
%end;
%mend check_exists;
When you run this macro, it will return “Dataset Exists” if a dataset exists.
Otherwise, it will return Does Not Exist.”
The following example shows how to use this macro in practice.
Example: Check if Dataset Exists in SAS
Suppose we create the following dataset in SAS called data1:
/*create dataset*/
data data1;
input hours score;
datalines;
1 64
2 66
4 76
5 73
5 74
6 81
6 83
7 82
8 80
10 88
;
run;
/*view dataset*/
proc printdata=data1;
We can define the following macro to check if a dataset exists:
%macro check_exists(data);
%if%sysfunc(exist(&data.)) %then%do;
%put Dataset Exists;
%end;
%else%do;
%put Dataset Does Not Exist;
%end;
%mend check_exists;We can then run this macro to check if the dataset called data1 exists:
/*check if dataset called data1 exists*/
%check_exists(data1);
When we view the log, we can see that the macro returns Does Exist since data1 does indeed exist:

Now suppose we also run the macro to check if a dataset called data2 exists:
/*check if dataset called data2 exists*/
%check_exists(data2);
Note: You can find the complete documentation for the EXIST function in SAS .
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). Does a dataset exist in SAS? (With an example). PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/does-a-dataset-exist-in-sas-with-an-example/
stats writer. "Does a dataset exist in SAS? (With an example)." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/does-a-dataset-exist-in-sas-with-an-example/.
stats writer. "Does a dataset exist in SAS? (With an example)." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/does-a-dataset-exist-in-sas-with-an-example/.
stats writer (2024) 'Does a dataset exist in SAS? (With an example)', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/does-a-dataset-exist-in-sas-with-an-example/.
[1] stats writer, "Does a dataset exist in SAS? (With an example)," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. Does a dataset exist in SAS? (With an example). PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
