Hi I posted this question on another forum. I asked how to do it in R. I would like to do it in SAS as well. Ids are duplicated because of multiple types in another column. I would like to remove duplicate ids and have an indicator column for specific types instead. Here's what I have and need (written in R): have<-data.frame(id=c(1,1,2,3,3,3,4,5,5,6))
have$type<-c("healthy","healthy","injury1","healthy","injury2",
"injury1","healthy","injury2","healthy","injury2")
need<-data.frame(id=c(1,2,3,4,5,6))
need$injury_ind<-c(0,1,1,0,1,1) Solution (written in R): have %>%
group_by(id) %>%
summarise(injury_id = +(any(type %in% c('injury1', 'injury2'))))
# A tibble: 6 x 2
# id injury_id
# <dbl> <int>
#1 1 0
#2 2 1
#3 3 1
#4 4 0
#5 5 1
#6 6 1 Any help would be appreciated.
... View more