How can I create an empty dataset in SAS? 2

How can I create an empty dataset in SAS?

To create an empty dataset in SAS, you can use the “DATA” statement followed by the desired name for your dataset. After the name, include a semicolon to indicate the end of the statement. This will create a new, empty dataset with no variables or observations. To add variables, you can use the “INPUT” statement followed by the desired variable names and their data types. To add observations, you can use the “SET” statement followed by the name of an existing dataset. This will populate your empty dataset with the same variables and observations as the existing dataset. Alternatively, you can use the “OUTPUT” statement to create a new dataset and specify the desired variables and their data types. This will also create an empty dataset with the specified variables. Overall, creating an empty dataset in SAS involves using specific statements to either add variables or copy existing datasets, depending on your needs.

Create an Empty Dataset in SAS


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 contentsdata=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:

Cite this article

stats writer (2024). How can I create an empty dataset in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-create-an-empty-dataset-in-sas/

stats writer. "How can I create an empty dataset in SAS?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-create-an-empty-dataset-in-sas/.

stats writer. "How can I create an empty dataset in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-create-an-empty-dataset-in-sas/.

stats writer (2024) 'How can I create an empty dataset in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-create-an-empty-dataset-in-sas/.

[1] stats writer, "How can I create an empty dataset in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I create an empty dataset in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top