{
  "name": "Loop statements in SAS, R and Python (counted, conditional, early exit)",
  "description": "Side-by-side list of the counted-loop, conditional-loop and early-exit statements of SAS, R and Python, compiled from the SAS 9.4 Statements Reference, the R base manual and the Python tutorial.",
  "page": "https://casrai.org/guides/do-loop-in-sas",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-17T12:15:29Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Loop feature",
      "unit": "",
      "description": ""
    },
    {
      "name": "SAS",
      "unit": "",
      "description": ""
    },
    {
      "name": "R",
      "unit": "",
      "description": ""
    },
    {
      "name": "Python",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Loop feature": "Counted loop",
      "SAS": "do i=1 to 10;",
      "R": "for(var in seq) expr",
      "Python": "for i in range(5)"
    },
    {
      "Loop feature": "Loop over an explicit list of values",
      "SAS": "do month='JAN','FEB','MAR';",
      "R": "for(var in seq) expr (each element of seq)",
      "Python": "for w in words:"
    },
    {
      "Loop feature": "Condition tested before each pass",
      "SAS": "do while(expr);",
      "R": "while(cond) expr",
      "Python": "while"
    },
    {
      "Loop feature": "Exit the loop early",
      "SAS": "leave;",
      "R": "break",
      "Python": "break"
    }
  ],
  "sources": [
    {
      "title": "SAS 9.4 Statements Reference: DO Statement, Iterative",
      "url": "https://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/p1cydk5fq0u4bfn1xfbjt7w1c7lu.htm",
      "accessed": "2026-11-17"
    },
    {
      "title": "R base manual: Control Flow",
      "url": "https://stat.ethz.ch/R-manual/R-devel/library/base/html/Control.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "The Python Tutorial: More Control Flow Tools",
      "url": "https://docs.python.org/3/tutorial/controlflow.html",
      "accessed": "2026-11-17"
    }
  ]
}