Published on :
ETL SASHELP

SAS Table Manipulation (Filtering, Selection, and Formatting)

This code is also available in: Deutsch Español Français
Awaiting validation
This educational script illustrates three common data manipulation operations in SAS©: 1) Filtering rows (observations) based on a condition, 2) Selecting specific columns (variables) to keep or drop, 3) Applying permanent formats to variables to control their display.
Data Analysis

Type : SASHELP


All steps use the standard example table sashelp.class provided with SAS.

1 Code Block
DATA STEP Data
Explanation :
Creates the 'myclass' table by reading 'sashelp.class' and keeping only observations where the 'age' variable is greater than or equal to 15.
Copied!
1DATA myclass;
2 SET sashelp.class;
3 where age >= 15;
4RUN;
2 Code Block
DATA STEP Data
Explanation :
Creates the 'myclass' table by keeping only the 'name', 'age', and 'height' variables from the source. The DROP statement is included as a commented alternative.
Copied!
1DATA myclass;
2 SET sashelp.class;
3 keep name age height;
4 *drop sex weight;
5RUN;
3 Code Block
DATA STEP Data
Explanation :
Creates the 'myclass' table and applies permanent display formats: 1 decimal for 'height' (total length 4) and no decimals for 'weight' (total length 3).
Copied!
1DATA myclass;
2 SET sashelp.class;
3 FORMAT height 4.1 weight 3.;
4RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.