The script begins by creating a temporary dataset named 'amit' using a DATA STEP with embedded data (cards). It contains observations with identifiers (id) and names (name) that may be duplicated. Then, two PROC SORT calls are made. The first uses the NODUP option to remove observations that are exact duplicates across all variables. The second uses the NODUPKEY option to remove observations that have the same value for the variable specified in the BY statement (here, 'id'), while retaining the first occurrence.
Data Analysis
Type : CREATION_INTERNE
The data is created directly within the SAS script using the 'cards;' statement within a DATA STEP. The 'amit' dataset is generated in memory.
1 Code Block
DATA STEP Data
Explanation : This code block uses a DATA STEP to create a SAS dataset named 'amit'. The variables 'id' (numeric), 'name' (character string), and 'amount' (numeric) are defined. The data is then read directly from the script via the 'cards;' statement.
Copied!
data amit;
input id name $ amount;
cards;
1 Amit 22
1 Amit 22
1 Amit 23
2 Amit 23
;
run;
1
DATA amit;
2
INPUT id name $ amount;
3
CARDS;
4
1 Amit 22
5
1 Amit 22
6
1 Amit 23
7
2 Amit 23
8
;
9
RUN;
2 Code Block
PROC SORT
Explanation : This block uses the PROC SORT procedure to sort the 'amit' dataset. The 'nodup' option is specified to remove observations that are exact duplicates across all variables of the observation. The resulting dataset, 'nodup', contains the unique observations. Sorting is performed by the 'id' variable.
Copied!
proc sort data=amit nodup out=nodup;
by id;
run;
1
PROC SORTDATA=amit nodup out=nodup;
2
BY id;
3
RUN;
3 Code Block
PROC SORT
Explanation : This block also uses the PROC SORT procedure. The 'nodupkey' option is used to remove observations with duplicate values for the variable(s) specified in the BY statement (here, 'id'). Unlike 'nodup', 'nodupkey' only considers the sort key for deduplication. The resulting dataset is 'nodupkey'.
Copied!
proc sort data=amit nodupkey out=nodupkey;
by id;
run;
1
2
PROC SORT
3
DATA=amit nodupkey out=nodupkey;
4
BY id;
5
RUN;
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.
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.