{
  "name": "SAS 9 string-extraction functions: syntax and handling of omitted or out-of-range arguments",
  "description": "Compares SUBSTR (extraction and replacement), SUBSTRN, %SUBSTR and SCAN as described in the SAS 9 documentation, compiled from the vendor's function reference pages: syntax, what an omitted length does, and what happens with out-of-range arguments.",
  "page": "https://casrai.org/guides/sas-substring",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-16T22:07:37Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Function",
      "unit": "",
      "description": ""
    },
    {
      "name": "Syntax",
      "unit": "",
      "description": ""
    },
    {
      "name": "Omitted length or default",
      "unit": "",
      "description": ""
    },
    {
      "name": "Out-of-range behaviour",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Function": "SUBSTR (right of =)",
      "Syntax": "variable=SUBSTR(string, position)",
      "Omitted length or default": "Remainder of the string from position",
      "Out-of-range behaviour": "Length zero, negative or too large returns the remainder, sets _ERROR_=1 and writes a log note"
    },
    {
      "Function": "SUBSTR (left of =)",
      "Syntax": "SUBSTR(variable, position)=characters-to-replace",
      "Omitted length or default": "Uses all characters on the right side of the equals sign",
      "Out-of-range behaviour": "Length cannot exceed the remaining length after position; undeclared variable gets default length 8"
    },
    {
      "Function": "SUBSTRN",
      "Syntax": "SUBSTRN(string, position)",
      "Omitted length or default": "Remainder of the string from position",
      "Out-of-range behaviour": "Non-positive position starts at first character (shortened); non-positive length gives zero-length result; past end is truncated"
    },
    {
      "Function": "%SUBSTR",
      "Syntax": "%SUBSTR(argument, position)",
      "Omitted length or default": "Text to the end of the argument",
      "Out-of-range behaviour": "Position beyond string: warning and null value; length beyond string: warning and characters to the end"
    },
    {
      "Function": "SCAN",
      "Syntax": "SCAN(string, count)",
      "Omitted length or default": "Default delimiters are blank and ! $ % & ( ) * + , - . / ; < ^ |; default DATA step result length 200",
      "Out-of-range behaviour": "Count beyond the number of words returns a single blank in a DATA step; negative count scans right to left"
    }
  ],
  "sources": [
    {
      "title": "SAS 9 SUBSTR function (right of =)",
      "url": "https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a000212264.htm",
      "accessed": "2026-11-12"
    },
    {
      "title": "SAS 9.3 SUBSTR function (left of =)",
      "url": "https://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0uev77ebdwy90n1rsd7hwjd2qc3.htm",
      "accessed": "2026-11-12"
    },
    {
      "title": "SAS SUBSTRN function",
      "url": "https://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0wqoixcwtx2jqn1ovqf06kart0o.htm",
      "accessed": "2026-11-12"
    },
    {
      "title": "SAS %SUBSTR function",
      "url": "https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/z3514substr.htm",
      "accessed": "2026-11-12"
    },
    {
      "title": "SAS SCAN function",
      "url": "https://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/p0jshdjy2z9zdzn1h7k90u99lyq6.htm",
      "accessed": "2026-11-12"
    }
  ]
}