Published on :
Data Manipulation CREATION_INTERNE

Creation and Sorting of the CLASSTEST Table

This code is also available in: Deutsch Español Français
Awaiting validation
The script first generates a table named 'classtest' containing student grades (Name, Subject, Score) using embedded data (datalines). It then displays this raw table. Next, it uses the SORT procedure to organize records in ascending order by 'Name' then by 'Subject', storing the result in a new table 'classtest_sort', which is then displayed.
Data Analysis

Type : CREATION_INTERNE


Data is entered directly into the script via the DATALINES4 instruction.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'classtest' work table from raw data included in the code. Display of the unsorted table.
Copied!
1DATA classtest;
2 INFILE DATALINES dsd;
3 INPUT
4 Name :$7.
5 Subject :$7.
6 Score;
7datalines4;
8Judy,Reading,91
9Judy,Math,79
10Barbara,Math,90
11Barbara,Reading,86
12Barbara,Math,90
13Louise,Math,72
14Louise,Reading,65
15William,Math,61
16William,Reading,71
17Henry,Math,62
18Henry,Reading,75
19Henry,Reading,84
20Jane,Math,94
21Jane,Reading,96
22;;;;
23RUN;
24 
25title "CLASSTEST table before sorting";
26PROC PRINT DATA=classtest;
27RUN;
28title;
2 Code Block
PROC SORT Data
Explanation :
Sorting of the 'classtest' table by 'Name' and 'Subject' variables. The result is saved in the 'classtest_sort' table and then displayed.
Copied!
1PROC SORT DATA=classtest out=classtest_sort;
2 BY Name Subject;
3RUN;
4 
5title "CLASSTEST_SORT table sorted by ascending Name and Subject";
6PROC PRINT DATA=classtest_sort;
7RUN;
8title;
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.