/********************************************************************* Goal: Identify duplicate and nonduplicate observations in a data set and write each to the appropriate data set. Strategy: Use FIRST.variable and LAST.variables made available in BY group processing. Documentation: "Combining and Modifying SAS Data Sets", Example 5.2 **********************************************************************/ /* Input data set */ data clasdata ; input id name $ class $ ; cards; 3456 Amber Chem101 3456 Amber Math102 3456 Amber Math102 4567 Denise ENGL201 4567 Denise ENGL201 2345 Ginny CHEM101 2345 Ginny ENGL201 2345 Ginny MATH102 1234 Lynn CHEM101 1234 Lynn CHEM101 1234 Lynn MATH102 5678 Rick CHEM101 5678 Rick HIST300 5678 Rick HIST300 ; /* Sort CLASDATA by NAME and CLASS */ proc sort ; by name class ; /* Subdivide CLASDATA */ data dups nodups ; set clasdata ; by name class ; /* Compare the values of the FIRST.CLASS and LAST.CLASS variables. Write an observation to NODUPS or DUPS, depending on the outcome of the comparison. */ if first.class and last.class then output nodups ; else output dups ; run; /* Print resulting data sets */ title "DUPS" ; proc print data=dups ; run ; title "NODUPS" ; proc print data=nodups ; run ;