Differences between revisions 1 and 2
Revision 1 as of 2019-12-06 02:09:48
Size: 996
Comment: Initial commit
Revision 2 as of 2019-12-06 02:17:46
Size: 1172
Comment:
Deletions are marked like this. Additions are marked like this.
Line 63: Line 63:
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.)`.

SAS Data Model

The data model for SAS is:

  • Read a row of data
  • Process statements sequentially
  • On run, write data into the step's LIBREF.TABLE

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

SAS/DataStep (last edited 2023-03-30 20:36:31 by DominicRicottone)