There are two common ways to create an empty dataset in SAS:
Method 1: Create Empty Dataset from Scratch
data empty_data;
attrib
var1 length=8 format=best12. label="var1"
var2 length=$30 format=$30. label="var2"
var3 length=8 format=best12. label="var3"
stop;
run;
Method 2: Create Empty Dataset from Existing Dataset
data empty_data;
set existing_data;
stop;
run;
In both methods, the stop statement prevents SAS from actually processing any rows.
This results in an empty dataset with variable names but no rows.
The following examples show how to use each method in practice.
Example 1: Create Empty Dataset from Scratch
We can use the following code to create an empty dataset called empty_data that contains four variables:
/*create empty dataset*/
data empty_data;
attrib
employee_ID length=8 format=best12. label="Employee ID"
employee_Name length=$30 format=$30. label="Employee Name"
sales length=8 format=best12. label="Sales"
sales_date length=8 format=date9. label="Sales Date";
stop;
run;
We can then use proc contents to view the contents of the dataset:
/*view contents of dataset*/
proc contents data=empty_data;
From the output we can see that the dataset has four variables but zero observations, i.e. zero rows.
At the bottom of the output we can also see the names of the four variables we created:
Example 2: Create Empty Dataset from Existing Dataset
We can use the following code to create an empty dataset called empty_data that is generated from an existing dataset called Comet, which is a dataset built into SAS:
/*create empty dataset from existing dataset*/
data empty_dat;
set sashelp.Comet;
stop;
run;
We can then use proc contents to view the contents of the dataset:
/*view contents of dataset*/
proc contents data=empty_data;
From the output we can see that the dataset has four variables but zero observations.
At the bottom of the output we can also see the names of the four variables created from the existing dataset:
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Use Proc Summary in SAS
How to Rename Variables in SAS
How to Create New Variables in SAS