Recoding in R

https://dplyr.tidyverse.org/reference/recode.html

# For character values, recode values with named arguments only. Unmatched # values are unchanged. char_vec <- sample(c("a", "b", "c"), 10, replace = TRUE) recode(char_vec, a = "Apple")
#> [1] "Apple" "b" "Apple" "b" "c" "Apple" "c" "c" "b" #> [10] "Apple"
recode(char_vec, a = "Apple", b = "Banana")
#> [1] "Apple" "Banana" "Apple" "Banana" "c" "Apple" "c" "c" #> [9] "Banana" "Apple"

 

My example:

court2qe$abc2<-recode(
court2qe$abc,"this is" = "X",
"That is" = "Y")

SAS PROC SQL -- merging and calculation

proc sql ;
create table new as
select a._Material_Substance_Use_Abuse,
(a._1_Yes+a._2_No) as total_n, a._1_Yes as Yes_n, a._2_No as No_n,
a._3_Section_not_available as No_no_section,
(a._1_Yes/(a._1_Yes+a._2_No)) as YES_percentage_wo_sec,
(a._1_Yes/(a._1_Yes+a._2_No+a._3_Section_not_available)) as YES_percentage_w_sec
from Eye_twoT1 AS a
;

SAS PROC SQL

Get the number of distinct values.

proc sql;
create table temp2 as select *,
count(distinct ID) as duplic
from final.cleaned
group by Case_num;
run;