How to Create an Empty Dataset in SAS

Creating an empty dataset in SAS is very simple. All that is required is to define a dataset name with the data statement, followed by a run command. The dataset will then be created in the library and can be filled with data afterward. Additionally, a few attributes can be specified upfront such as the column names and data types. This will create a dataset with the provided attributes, but no data.


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 , 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:

The following tutorials explain how to perform other common tasks in SAS:

x