Rabidwolff's Alehouse
"Your place for fun and knowledge."
HOME | Quotes | SAS | C# | BEER



Basics
FORMATS
INFORMATS
DATETIME
ATTRIB
LENGTH
FORMAT
INFORMAT
LABEL
JOINS
OPERATORS

Statements
RETAIN
FIRST.
LAST.

Procedures
PROC SORT
PROC COPY
PROC CPORT
IF ELSE
PROC REPORT

Functions
CAT
CATS
CATT
CATX

CDISC
Random Q & A

CDISC
CDISC Info

Coded Tools
XML Output
Examples

RETAIN

The RETAIN statement is used to hold values from a previous record’s variable to the next.

  • If left uninitialized then the first observation’s value will be missing
  • Has no effect of variables read from the SET, MERGE, or UPDATE statements
  • Typically used with FIRST. and LAST. statements within a BY-Group, see below

FIRST. & LAST.

The FIRST. And LAST. statements are used with the BY-Group processing of a data step. FIRST. statement is bool that equals 1 if it is the first value present per BY group variable and 0 if it is not. The LAST. statement works the same only for the last value for a variable per the BY group.

Example Code:


Example 'test' Dataset:
Site SubjID Sex Weight SumWeight FirstSite LastSite
1 1 F 130 130 1 0
1 2 M 200 330 0 1
2 3 F 150 150 1 0
2 4 F 180 330 0 0
2 5 M 260 590 0 1
3 6 M 150 150 1 1

Rabidwolff Industries | Establisted: 10/15/2011 | Version: 4 8/4/2012 | Page Last Generatated: 9/25/2021 5:02:02 PM