Announcement Icon Online training class for Clinical R programming batch starts on Monday, 02Feb2026. Click here for details.

Replicating the concept of usage of loops for dummy data creation


Lesson Description
-
  • Sometimes, we want to work with the concept of "Replicating the concept of usage of loops for dummy data creation" in a clear, repeatable way.
  • This lesson walks through a simple example and shows the key steps.
  • We will see one approach on how we can do it in SAS and R.
data loop;
    do treatment=1,3,5;
        do avisitn=0,1,2,8;
            output;
        end;
    end;
run;
library(tidyverse)

 

loop <- crossing(treatment = c(1, 3, 5), avisitn = c(0, 1, 2, 8))
loop <- expand.grid(
  treatment = c(1, 3, 5),
  avisitn = c(0, 1, 2, 8)
)
  • expand.grid() creates all combinations of treatment and visit values.