Published on :
ETL CREATION_INTERNE

Creating and Displaying School Grade Data

This code is also available in: Deutsch Español Français
Awaiting validation
The script is divided into five logical sections, each creating and displaying a data table (Grades1 to Grades5). The first section shows simple creation and display. Subsequent sections introduce the use of the VAR statement in PROC PRINT to select and order columns. One section demonstrates how to calculate a new variable (totalscores) within a DATA STEP. The last section shows how to modify the value of an existing column. This script is a good example for beginners learning the fundamentals of DATA STEP and the PRINT procedure.
Data Analysis

Type : CREATION_INTERNE


All data is created and integrated directly into the SAS script using the `DATALINES` statement within each DATA STEP. No external data source is required or used.

1 Code Block
DATA STEP Data
Explanation :
This code block creates a SAS table named `Grades1`. The `input` statement defines the data structure by reading variables from specific column positions. Data is provided directly in the code via `DATALINES`.
Copied!
1DATA Grades1;
2 INPUT subj 1-4 name $ 5-23 sex exam1 exam2 exam3 exam4 exam5 project finalexam;
3 DATALINES;
41011 Alia Bhatt 2 100 65 83 84 99 91 96
51012 Maria Smith 1 78 82 86 . 100 95 97
61111 Thomas Jones 2 88 81 96 69 91 90 98
71121 Benedictine Arnold 2 68 82 82 89 89 93 99
81301 Trisha Gupta 1 51 69 79 59 85 64 100
9;
10RUN;
2 Code Block
PROC PRINT
Explanation :
This procedure displays the entire content of the `Grades1` table in the results output window.
Copied!
1PROC PRINT DATA=Grades1;
2RUN;
3 Code Block
DATA STEP Data
Explanation :
Creates a second table `Grades2`, identical to `Grades1`, to demonstrate a different display functionality.
Copied!
1DATA Grades2;
2 INPUT subj 1-4 name $ 5-23 sex exam1 exam2 exam3 exam4 exam5 project finalexam;
3 DATALINES;
41011 Alia Bhatt 2 100 65 83 84 99 91 96
51012 Maria Smith 1 78 82 86 . 100 95 97
61111 Thomas Jones 2 88 81 96 69 91 90 98
71121 Benedictine Arnold 2 68 82 82 89 89 93 99
81301 Trisha Gupta 1 51 69 79 59 85 64 100
9;
10RUN;
4 Code Block
PROC PRINT
Explanation :
Displays the `Grades2` table. The `var` statement is used to specifically select the columns to display and define their order.
Copied!
1 
2PROC PRINT
3DATA=Grades2;
4var name exam1 exam2 exam3 exam4 project finalexam;
5RUN;
6 
5 Code Block
DATA STEP Data
Explanation :
Creates a third table `Grades3` to illustrate another variation of column display.
Copied!
1DATA Grades3;
2 INPUT subj 1-4 name $ 5-23 sex exam1 exam2 exam3 exam4 exam5 project finalexam;
3 DATALINES;
41011 Alia Bhatt 2 100 65 83 84 99 91 96
51012 Maria Smith 1 78 82 86 . 100 95 97
61111 Thomas Jones 2 88 81 96 69 91 90 98
71121 Benedictine Arnold 2 68 82 82 89 89 93 99
81301 Trisha Gupta 1 51 69 79 59 85 64 100
9;
10RUN;
6 Code Block
PROC PRINT
Explanation :
Displays the `Grades3` table and uses the `var` statement to reorder columns in a different order than their natural order in the table.
Copied!
1 
2PROC PRINT
3DATA=Grades3;
4var name project finalexam exam1 exam2 exam3 exam4;
5RUN;
6 
7 Code Block
DATA STEP Data
Explanation :
Creates the `Grades4` table. A new variable `totalscores` is calculated by summing the scores from exams, project, and final exam. Note that if one of the calculation variables is missing ('.') as for 'Maria Smith', the `totalscores` result will be missing.
Copied!
1DATA Grades4;
2 INPUT subj 1-4 name $ 5-23 sex exam1 exam2 exam3 exam4 exam5 project finalexam;
3 totalscores = exam1 + exam2 + exam3 + exam4 + exam5 + project + finalexam;
4 DATALINES;
51011 Alia Bhatt 2 100 65 83 84 99 91 96
61012 Maria Smith 1 78 82 86 . 100 95 97
71111 Thomas Jones 2 88 81 96 69 91 90 98
81121 Benedictine Arnold 2 68 82 82 89 89 93 99
91301 Trisha Gupta 1 51 69 79 59 85 64 100
10;
11RUN;
8 Code Block
PROC PRINT
Explanation :
Displays the `Grades4` table, including the newly calculated `totalscores` column to verify the calculation result.
Copied!
1 
2PROC PRINT
3DATA=Grades4;
4var name exam1 exam2 exam3 exam4 project finalexam totalscores;
5RUN;
6 
9 Code Block
DATA STEP Data
Explanation :
Creates the `Grades5` table. In this DATA STEP, the value of the existing variable `exam2` is modified by adding 1 to it for each observation.
Copied!
1DATA Grades5;
2 INPUT subj 1-4 name $ 5-23 sex exam1 exam2 exam3 exam4 exam5 project finalexam;
3 exam2 = exam2 + 1;
4 DATALINES;
51011 Alia Bhatt 2 100 65 83 84 99 91 96
61012 Maria Smith 1 78 82 86 . 100 95 97
71111 Thomas Jones 2 88 81 96 69 91 90 98
81121 Benedictine Arnold 2 68 82 82 89 89 93 99
91301 Trisha Gupta 1 51 69 79 59 85 64 100
10;
11RUN;
10 Code Block
PROC PRINT
Explanation :
Displays the `Grades5` table to visualize the result of the modification made to the `exam2` column.
Copied!
1 
2PROC PRINT
3DATA=Grades5;
4var name exam1 exam2 exam3 exam4 project finalexam ;
5RUN;
6 
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.
Banner
Expert Advice
Expert
Stéphanie
Spécialiste Machine Learning et IA.
« This script serves as the foundational blueprint for SAS programming. It perfectly illustrates the primary SAS workflow: reading raw data, performing logical transformations in the DATA step, and generating structured reports via PROC PRINT. »