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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.