I have the following input dataset
ID Var1 Var2
11 A 23
11 B 121
11 A 23
12 A 32
12 B 158
12 A 32
12 B 158
13 A 87
13 B 567
I want to remove the repetitive records by ID variable and get the following output.
ID Var1 Var2
11 A 23
11 B 121
12 A 32
12 B 158
13 A 87
13 B 567
Please suggest the best way to do it.
Not possible. SAS will not allow two variables with the same name.
If the third column is VAR2:
data have; input ID Var1 $ Var2 ; datalines; 11 A 23 11 B 121 11 A 23 12 A 32 12 B 158 12 A 32 12 B 158 13 A 87 13 B 567 ;
Then easiest code is:
proc sort data=have out=want nodupkey; by id var1 var2; run;
The NODUPKEY option tells SAS to sort the data but only allow one observation with each combination of the BY variables in the OUT= data set.
There are options to send the deleted observations to a different output set.
Not possible. SAS will not allow two variables with the same name.
If the third column is VAR2:
data have; input ID Var1 $ Var2 ; datalines; 11 A 23 11 B 121 11 A 23 12 A 32 12 B 158 12 A 32 12 B 158 13 A 87 13 B 567 ;
Then easiest code is:
proc sort data=have out=want nodupkey; by id var1 var2; run;
The NODUPKEY option tells SAS to sort the data but only allow one observation with each combination of the BY variables in the OUT= data set.
There are options to send the deleted observations to a different output set.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.