Hi All, I am trying to run correlation analysis in SAS that was previously done in R. I need to subset the dataset before the analysis, and I am having trouble understanding the R code for subsetting the dataset. Could anyone please help me to interpret the code and suggest equivalent code in SAS? I have a knowledge of Base SAS and very little knowledge of R. Also, I am not very good at DO loop. I need to reproduce the following result from R to SAS: for(i in unique(data$Site)){ sum1_alternate <- sum1 <- sum2 <- sum3_alternate <- 0 for(j in unique(data[data$Site==i,]$id)){ if(unique(data[data$site==i & data$id==j,]$ind)==1){ ind1_alternate <- ifelse(j %in% temp$id, 1, 0) sum1_alternate<- sum1_alternate + ind1_alternate if(ind1_alternate == 1){ ind1 <- ifelse(min(temp[temp$id==j,]$age)<21, 1, 0) sum1 <- sum1+ind1 ind2 <- ifelse(min(temp[temp$id==j,]$age)>21, 1, 0) sum2 <- sum2+ind2 } } i f(unique(data[data$site==i & data$id==j,]$ind)==0){ sum3_alternate <- sum3_alternate+1 #sum_info <- summary(data[data$site==i & data$id==j,]$age) } } sum1_alternate_site <- c(sum1_alternate_site, sum1_alternate) sum1_site <- c(sum1_site, sum1) sum2_site <- c(sum2_site, sum2) sum3_alternate_site <- c(sum3_alternate_site, sum3_alternate) #sum3_site <- c(sum3_site, sum3) } percent1 <- sum1_alternate_site/(sum1_alternate_site+sum3_alternate_site) percent2 <- sum1_site/(sum1_site+sum2_site+sum3_alternate_site) plot(site_mean$x, percent1, xlab="Mean Age", ylab="Percentage of surgery", main="mean age vs percentage of surgery") abline(lm(percent1 ~ site_mean$x)) cor.test(percent1, site_mean$x) plot(site_mean$x, percent2, xlab="Mean Age", ylab="Percentage of surgery", main="mean age vs percentage of surgery <21 year-old") abline(lm(percent2 ~ site_mean$x)) cor.test(percent2, site_mean$x) Thanks.
... View more