R-Guru Smile design: how to one in SIlhouette Studio ยป Smart Silhouette Resource Hub

  • Home
  • Compare with SAS

Compare with SAS

With so many SAS programmers learning R, it makes sense that an R SAS package was created.  With the SASSY package, SAS programmers can have a more seamless transition between R and SAS.  With the SASSY package, SAS programmers can almost replicate reviewing logs, reviewing datasets, and program data steps, formats and reports.  There are R packages and functions to replicate Proc Freq, Proc Means and Proc Report.  It is important to realize that although SAS has tools to integrate with R and R has packages to replicate SAS programming, the objective of learning R is to consider it a standalone complete toolbox in its own right that can be used entirely independent of SAS.

          Similar to SAS, R functions resemble many features of the Data Step.


                      




          TASK

          R

          SAS

          Rounding 2.5

          2 (even number)

          3 (up)

          Sorting Missing Values

          ‘NA’ is last obs unless converted to missing

          Missing is first obs


          Compare and Contrast SAS Procedures and R Functions

          proc print data=d1; var _all_; run; d1 displays all records, head

          (d1)  displays first 5 records, tail(d1) displays the last few records

          To subset, first create R object based on subset and selected variables and then display all records

          proc freq data=d1; tables sex*race; run;

          table(d1$sex, d1$race)

          prop.table()

          proc univariate;

          summary(d1)

          proc sort data=dm2; by sex race; run;

          dm2[order(dm1$sex, dm1$race)] 

           proc format;

          In Vectors: sex_code <- c(‘M’, ‘M’, ‘M’, ‘F’, ‘M’) # 1. data values in simple vector to store data values

          sex_decode <- c(‘M’=’Male’, ‘F’=’Female’) # 2. named vector data = ‘label’ for values similar to proc format

          sex <- sex_decode[sex_code] # 3. converts values to labels sex_code vector is subset of sex_code vector


          As Functions: age_cat <- vectorize(function(x) { # x is input value

          if (x < 18) { # condition

          ret <- "< 18" # return label

          } else if (x >= 18 & x < 24) {

          ret <- "18 to 24"

          } else if (x >= 24 & x < 45) {

          ret <- "24 to 45"

          } else if (x >= 45 & x < 60) {

          ret <- "45 to 60"

          } else if (x >= 60) {

          ret <- "> 60"

          } else {

          ret <- "Unknown"

          }

          return(ret) })

          df$age_cat <- age_cat(df$age) # apply function to age variable to create age_cat variable 

          proc means;

          summarise(AllPages = sum(Pages),

          AvgLength = mean(Pages),

          AvgRating = mean(MyRating),

          AvgReadTime = mean(read_time),

          ShortRT = min(read_time),

          LongRT = max(read_time),

          TotalAuthors = n_distinct(Author)) 

           proc contents;

          library(hmisc)

          content(dm)

           proc compare;

          cmp <- comparedf(mockstudy, mockstudy2, by = "case", tol.vars = c("._ ", "case"), int.as.num = TRUE)

          n.diffs(cmp) 

           proc report;

          flextable()

          Section Objectives

          • Understand and be able to apply SASSY Package for Tables, Lists and Graphs
          • Know how to apply SQL methods in R programming
          • Understand the difference between SAS macros and R programming
          • Know how to apply Tidyverse Package 
          Powered by Wild Apricot Membership Software