Table of Contents
The DATA Step is a fundamental component in SAS software that allows users to read, manipulate, and create data sets. It is a powerful tool that can be used to perform data transformation, data cleaning, and data analysis tasks. The DATA Step uses a programming language to create custom data sets, allowing for flexibility and customization in data management. It is a versatile and efficient method for processing large amounts of data and can be used to merge, sort, and filter data sets. With its wide range of functions and capabilities, the DATA Step is an essential feature for data management and analysis in SAS.
Use the DATA Step in SAS (With Examples)
You can use the DATA step in SAS to create datasets.
There are two common ways to use the DATA step:
1. Create a dataset from scratch.
2. Create a dataset from an existing dataset.
The following examples show how to use each method in practice.
Example 1: Use DATA Step to Create Dataset from Scratch
The following syntax shows how to use the DATA step to create a dataset with three variables:
/*create dataset*/
data my_data;
input team $ position $ points;
datalines;
A Guard 25
A Guard 20
A Guard 30
A Forward 25
A Forward 10
B Guard 10
B Guard 22
B Forward 30
B Forward 10
B Forward 10
B Forward 25
;
run;
/*view dataset*/
proc printdata=my_data;
Here is exactly what we did in this example:
First, we used data to name the dataset.
Then, we used input to specify the variable names ($ specifies a character variable).
Then, we used datalines to tell SAS that the upcoming lines represented values in the dataset.
Example 2: Use DATA Step to Create Dataset from Existing Dataset
We can use the data step along with the set statement to create a dataset from another dataset that already exists.
For example, we can use the following syntax to create a new dataset called new_data that uses the variables from the dataset called my_data but drops the ‘returns’ variable:
/*create new dataset that drops returns from my_data*/
data new_data;
set my_data;
drop returns;
run;
/*view dataset*/
proc printdata=new_data;
Here is exactly what we did in this example:
First, we used data to name the new dataset.
Then, we used set to specify the existing dataset to create the new dataset from.
Then, we used drop to drop the ‘returns’ variable from the new dataset.
The end result is a new dataset contains the exact same variables from the original dataset except the ‘returns’ variable has been dropped.
The following tutorials explain how to perform other common tasks in SAS:
Cite this article
stats writer (2024). How can the DATA Step be used in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-data-step-be-used-in-sas/
stats writer. "How can the DATA Step be used in SAS?." PSYCHOLOGICAL SCALES, 25 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-data-step-be-used-in-sas/.
stats writer. "How can the DATA Step be used in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-data-step-be-used-in-sas/.
stats writer (2024) 'How can the DATA Step be used in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-data-step-be-used-in-sas/.
[1] stats writer, "How can the DATA Step be used in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can the DATA Step be used in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
