DO loop vs. vectorization in SAS/IML Vectorization is an important skill for many matrix languages. From Rick Wiklin’s book about SAS/IML and his recent cheat sheet, I found a few new vector-wise functions since SAS 9.22. To compare the computation efficiency between the traditional do loop style and the vectorization style, I designed a simple test in SAS/IML: square a number sequence(from 1 to 10000) and calculate the time used. Two modules were written according to these two coding styles. Each module was repeated 100 times, and system time consumed was recorded by SAS/IML’s time() function. proc iml; start module1; * Build the first module; result1 ...
Benchmarking of the CUSUM function in SAS/IML Cumulative sums can be obtained in SAS’s DATA step by the RETAIN statement. As the codes below, a new variable of the cumulative values will be returned by DATA step’s implicit DO loop. data one; do i = 1 to 1e6; z = ranuni(0); output; end; drop i;run;data two; set one; retain y 0; y + z;run;The same logic can be realized by an explicit DO loop in SAS/IML. However, SAS/IML has a function CUSUM which is specially made for cumulative sums. To compare the efficiency of the two methods, I tried an experiment: calculating the cumulative sums for a ...
Random seeds A footnote toward Rick Wilkin’s recent article “How to Lie with a Simulation”. (Sit in front of a laptop w/o SAS; have to port all SAS/IML codes into R)Generated 10 seeds randomly to run Stochastic simulation of Buffon's needle experiment by Rick's method. Hardly converge any of them …. # Replicate Rick Wicklin's SAS/IML codes for Buffon's needle experiment simupi <- function(N, seed) { set.seed(seed) z <- matrix(runif(N*2, 0, 1), N, 2) theta <- pi*z[, 1] y <- z[, 2] / 2 P <- sum(y < sin(theta)/2) / N piEst <- 2/P Trials <- 1:N Hits <- (y < sin(theta)/2) ...
Merry Christmas! Just for fun.data cars; set sashelp.cars; length label $10.; keep invoice weight enginesize type label; if _n_ = 1 then label = 'Merry'; if _n_ = 50 then label = 'Christmas';run;proc sgplot data = cars noautolegend; bubble x = invoice y = weight size = enginesize / group = type datalabel = label datalabelattrs=(color=red family="garamond" style=italic size=45 weight= bold) transparency=0.4; xaxis max = 80000 label = ' '; yaxis label = ' ' max = 6000;run;
Those most productive R developers The number of R packages on CRAN is 3,483 on 2011-12-12. The growth of R package in the past years can be fitted by a quadratic regression perfectly. I am always interested in who are maintaining those packages. Then I wrote an R script to extract the package head information from CRAN’s website and stored them in a SQLite database. Most R developers are maintaining 1-3 R packages. Some of them are really productive. By the correspondence addresses (Email), the top 50 R developers are listed below:developer package1 Kurt Hornik 232 Martin Maechler 233 Hadley Wickham 214 Rmetrics Core Team ...