SAS Data Model

The data model for SAS is:

data LIBREF.TABLE;
    STATEMENTS;
run;

Quick Tips

Copying Tables

data LIBREF.NEWTABLE;
    set LIBREF.OLDTABLE;
run;


Subsetting Tables

data LIBREF.NEWTABLE;
    set LIBREF.OLDTABLE;
    where EXPR;
    keep VARLIST1;
    drop VARLIST2;
run;


Coercing Data Types

data LIBREF.NEWTABLE;
    set LIBREF.OLDTABLE;

    /* try converting alphanumeric to numeric */
    NUM_ID = input(ANUM_ID, 8.);

    /* left-align text */
    length TEXT_VAR $999.;
    TEXT_VAR = put(TEXT_VAR, $999. -L);

    /* parse timestamps like '01Jan1999' */
    format TIMESTAMP_VAR DATE9.;
    MONTH_VAR = month(TIMESTAMP_VAR);

    /* round numerics to integers */
    format INT_VAR 10.;
run;

The input function generates a variable _ERROR_ by default, flagging cases that could not be formatted. To suppress this variable's creation, use input(ANUM_ID, ?? 8.).


CategoryRicottone