What is the difference between nodup and nodupkey options?
Answer Posted / majid
data test1;
input id1 $ id2 $ extra ;
cards;
aa ab 3
aa ab 1
aa ab 2
aa ab 3
;
proc sort nodup data=test1;
by id1 ;
run;
proc print data=test1;
run;
output will be like this:
Obs id1 id2 extra
1 aa ab 3
2 aa ab 1
3 aa ab 2
4 aa ab 3
*nodup" is an alias for "noduprecs" which appears to
mean "no duplicate records" but there is no way sas can
know about these duplicate records unless they, by chance,
land next to each other in sequence It is a big mistake
to think sorting "nodup" will remove duplicate records.
Sometime it will, sometime it won't. The only way you can
be sure of removing duplicate records is to "proc sort
nodupkey" and include enough key variables to be sure you
will lose the duplicates you want to lose. In the case
shown above, then if we knew of the same "extra" values
being duplicates we wanted to remove then this variable
should be included in the list of sort variables and
then "nodupkey" will remove the duplicates as shown below.
;
proc sort nodup data=test1;
by id1 id2 extra;
run;
proc print data=test1;
run;
output will be like this:
Obs id1 id2 extra
1 aa ab 1
2 aa ab 2
3 aa ab 3
so as u can see nodup eliminated all duplicate observations
if you sort them by all variables but nodupkey will show
only the duplicate observation.
proc sort nodupkey data=test1;
by id1 ;
run;
options nocenter;
proc print data=test1;
run;
output will be like this:
Obs id1 id2 extra
1 aa ab 3
| Is This Answer Correct ? | 22 Yes | 6 No |
Post New Answer View All Answers
What is the work of tranwrd function?
What are the difference between the sas data step and sas procs?
What is the function of output statement in a SAS Program?
What sas features do you use to check errors and data validation?
Explain what is SAS informats?
In proc transpose and data step with arrays which one you pick?
for whom is sas data integration studio designed? : Sas-di
Can you explain the process of calendar?
If money were no object, what would you like to do?
What is the purpose of _character_ and _numeric_?
Mention the difference between ceil and floor functions in sas?
what is treatment emergent events and treatment emregent adverse event
what is snowflake schema? : Sas-di
Difference between nodup and nodupkey options?
What does proc print, and proc contents are used for?