Data Transformations ⏱️ 5 min read

Essential SAS Functions: SUBSTR, SCAN, STRIP, CEIL & FLOOR

Master core string slicing, token extraction, and numeric rounding operations in DATA steps.

Made2Stick
Made2Stick Editorial Team Reviewed by Senior SAS & Data Systems Faculty

📌 Direct Answer / Executive Definition

SAS built-in character and numeric functions perform row-level data transformations. Key string functions include SUBSTR (extracting substrings by character position), SCAN (extracting words by delimiter), and STRIP (removing leading and trailing blanks). Key numeric functions include CEIL, FLOOR, INT, and ROUND for precision handling.

🎬 Classroom Video Blueprint: Essential SAS Functions: SUBSTR, SCAN, STRIP, CEIL & FLOOR
Masterclass Frame
Essential SAS Functions: SUBSTR, SCAN, STRIP, CEIL & FLOOR Video Slide ▶ Watch in Video Player →

Why Robust String Slicing & Discretization Matter for Data Cleaning

Data cleaning and standardization in real-world pipelines require precise text slicing, phone/code parsing, and numeric discretization before feeding statistical procedures.

Standard Syntax, Derivation & Framework Pattern

/* String Parsing & Numeric Discretization */
DATA work.cleaned_records;
    SET work.raw_feed;
    
    /* Extract 3-letter site prefix and visit number */
    Site_Code = SUBSTR(Patient_Ref, 1, 3);
    Visit_Num = INPUT(SCAN(Patient_Ref, 2, '-'), 8.);
    
    /* Clean leading/trailing spaces */
    Full_Name = STRIP(First_Name) || ' ' || STRIP(Last_Name);
    
    /* Numeric rounding & truncation */
    Dose_Ceil  = CEIL(Raw_Dose);   /* Smallest integer >= value */
    Dose_Floor = FLOOR(Raw_Dose);  /* Largest integer <= value */
RUN;

Core Rules & Certification Takeaways

  • SUBSTR(string, start, length) extracts fixed-width characters starting at a 1-based index.
  • SCAN(string, n, delimiter) extracts the nth word delimited by specified characters regardless of position.
  • STRIP removes both leading and trailing whitespace, while TRIM removes only trailing spaces.
  • CEIL rounds up to the next integer; FLOOR rounds down; ROUND rounds to specified decimal precision.

🔗 Related Architectural Concepts & Next Steps

Deepen your mastery with connected topics across our curriculum and knowledge hubs.

Data Standards SAS
INFORMATS & Custom Format Decodes Read Guide →
Data Standards Clinical
SDTM Text Cleaning & ISO Dates Read Guide →
Core Engine SAS
PDV In-Memory String Operations Read Guide →

Frequently Asked Questions (FAQ)

What is the difference between SUBSTR and SCAN in SAS?

SUBSTR extracts characters based on exact starting position and length, whereas SCAN extracts words/tokens based on delimiter characters.

How does STRIP differ from TRIM in SAS?

TRIM removes only trailing blanks, whereas STRIP removes both leading and trailing whitespace from the string.

Want complete video breakdowns & exercises?

Explore full step-by-step masterclass training in The Simplest Guide to SAS Programming.

Enroll in SAS Masterclass →
← Back to SAS Programming Knowledge Hub Overview