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!
data classtest;
infile datalines dsd;
input
Name :$7.
Subject :$7.
Score;
datalines4;
Judy,Reading,91
Judy,Math,79
Barbara,Math,90
Barbara,Reading,86
Barbara,Math,90
Louise,Math,72
Louise,Reading,65
William,Math,61
William,Reading,71
Henry,Math,62
Henry,Reading,75
Henry,Reading,84
Jane,Math,94
Jane,Reading,96
;;;;
run;
title "CLASSTEST table before sorting";
proc print data=classtest;
run;
title;
1
DATA classtest;
2
INFILEDATALINES dsd;
3
INPUT
4
Name :$7.
5
Subject :$7.
6
Score;
7
datalines4;
8
Judy,Reading,91
9
Judy,Math,79
10
Barbara,Math,90
11
Barbara,Reading,86
12
Barbara,Math,90
13
Louise,Math,72
14
Louise,Reading,65
15
William,Math,61
16
William,Reading,71
17
Henry,Math,62
18
Henry,Reading,75
19
Henry,Reading,84
20
Jane,Math,94
21
Jane,Reading,96
22
;;;;
23
RUN;
24
25
title "CLASSTEST table before sorting";
26
PROC PRINTDATA=classtest;
27
RUN;
28
title;
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!
proc sort data=classtest out=classtest_sort;
by Name Subject;
run;
title "CLASSTEST_SORT table sorted by ascending Name and Subject";
proc print data=classtest_sort;
run;
title;
1
PROC SORTDATA=classtest out=classtest_sort;
2
BY Name Subject;
3
RUN;
4
5
title "CLASSTEST_SORT table sorted by ascending Name and Subject";
6
PROC PRINTDATA=classtest_sort;
7
RUN;
8
title;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.