Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions By Syntax/SORT Procedure/6_Remove duplicated rows by columns.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/************************************************************************************************
REMOVE DUPLICATED ROWS by COLUMNS
This program sort the input table by specified columns to ensure rows with same values in
these columns are adjacent. Furthermore, the sorting ensures that the first record in
the group has the highest value based on a column. Then, all subsequent (or duplicate)
rows based on specified columns are removed.
Keywords: PROC SORT, remove duplicates
SAS Versions: SAS 9, SAS Viya
Documentation: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=default&docsetId=proc&docsetTarget=p1nd17xr6wof4sn19zkmid81p926.htm
1. Create the WORK.CLASSTEST table and print it.
2. PROC SORT sorts rows by specified columns (here: Name) so that duplicated
rows will be sequential, and the first record in the group has the highest value for a
given column (here: Score).
3. Another PROC SORT step with the NODUPKEY option deletes rows with duplicate BY values
by the specified columns (here: Name), thus leaving only one row (here:the one with the
highest Score for each Name).
************************************************************************************************/


data classtest; /*1*/
infile datalines dsd;
input
Name :$7.
Subject :$7.
Score;
datalines4;
Judy,Reading,91
Judy,Math,79
Barbara,Math,90
Barbara,Reading,86
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;

proc sort data=classtest out=classtest_sort; /*2*/
by Name descending Score;
run;

proc sort data=classtest_sort out=classtest_nodup nodupkey; /*3*/
by Name;
run;
20 changes: 20 additions & 0 deletions By Syntax/UNIVARIATE Procedure/1_Extreme_Observations.sas
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/************************************************************************************************
PRINT EXTREME OBSERVATIONS
This program prints a specified amount of observations with the highest and lowest values
in a specified variable. It labels these observations with an identifier variable.
Keywords: PROC UNIVARIATE
SAS Versions: SAS 9, SAS Viya
Documentation: https://documentation.sas.com/doc/en/pgmsascdc/v_066/procstat/procstat_univariate_toc.htm
1. Specify the output table ODS should display from the following PROC UNIVARIATE step.
2. PROC UNIVARIATE prints the N (here: 3) observations from the specified input
(here: SASHELP.CLASS) table
3. Specify the variable based on which the highest and lowest observations are selected
(here: Height).
4. A specified (here: Name) variable is used to identify these observations.
************************************************************************************************/

ods select ExtremeObs; /*1*/
proc univariate data=sashelp.class nextrobs=3; /*2*/
var Height; /*3*/
id Name; /*4*/
run;