File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ /************************************************************************************************
2
+ REMOVE DUPLICATED ROWS by COLUMNS
3
+ This program sort the input table by specified columns to ensure rows with same values in
4
+ these columns are adjacent. Furthermore, the sorting ensures that the first record in
5
+ the group has the highest value based on a column. Then, all subsequent (or duplicate)
6
+ rows based on specified columns are removed.
7
+ Keywords: PROC SORT, remove duplicates
8
+ SAS Versions: SAS 9, SAS Viya
9
+ Documentation: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=default&docsetId=proc&docsetTarget=p1nd17xr6wof4sn19zkmid81p926.htm
10
+ 1. Create the WORK.CLASSTEST table and print it.
11
+ 2. PROC SORT sorts rows by specified columns (here: Name) so that duplicated
12
+ rows will be sequential, and the first record in the group has the highest value for a
13
+ given column (here: Score).
14
+ 3. Another PROC SORT step with the NODUPKEY option deletes rows with duplicate BY values
15
+ by the specified columns (here: Name), thus leaving only one row (here:the one with the
16
+ highest Score for each Name).
17
+ ************************************************************************************************/
18
+
19
+
20
+ data classtest ; /*1*/
21
+ infile datalines dsd;
22
+ input
23
+ Name :$7 .
24
+ Subject :$7 .
25
+ Score;
26
+ datalines4 ;
27
+ Judy,Reading,91
28
+ Judy,Math,79
29
+ Barbara,Math,90
30
+ Barbara,Reading,86
31
+ Louise,Math,72
32
+ Louise,Reading,65
33
+ William,Math,61
34
+ William,Reading,71
35
+ Henry,Math,62
36
+ Henry,Reading,75
37
+ Henry,Reading,84
38
+ Jane,Math,94
39
+ Jane,Reading,96
40
+ ;;;;
41
+ run ;
42
+
43
+ proc sort data=classtest out =classtest_sort; /*2*/
44
+ by Name descending Score;
45
+ run ;
46
+
47
+ proc sort data=classtest_sort out =classtest_nodup nodupkey ; /*3*/
48
+ by Name;
49
+ run ;
You can’t perform that action at this time.
0 commit comments