P-STAT: the Programming Language
PPL: In Brief
In P-STAT files can be modified any time they are input to
any P-STAT command. Thus, new variables can be generated or
existing variables recoded as the file is read by the REGRESSION
or SURVEY commands -- it does not require a separate data step!
Of course we have the following garden variety manipulations:
- KEEP or DROP variables
- GENERATE variables
- SET or RECODE variables to other values
- RENAME variables
- DO loops
- IF-THEN-ELSE blocks.
- Arithmetic functions
- Random number functions
- Date handling
We Also Have Some Prize Specimens
SPLIT and COLLECT are functions for manipulating
groups of related cases such as all of
the plots in a farm, all the people in a household or all
the employees in the department.
EXPAND is a PPL statement that projects the values of one or more input
variables into a set of new variables, each associated with a specified
value in the input variables.
make it easy to pass
information between cases in a single file, between files and
even between commands.
A full suite of character functions is available:
- UPPER and LOWER
- LEFT, RIGHT and CENTER
- SUBSTRING and POSITION
- CHANGE, COMPRESS, BLANK and PAD
TOKEN returns a piece of a string, where piece is usually
defined as blank delimited. The delimiter and the position of
the token can be specified. For example the following retrieves
the month from a date in the form dd/mm/yy:
Month = TOKEN ( date, 2, '/' )
MATCHES provides pattern matching capabilities that are usually found
in languages such as grep and awk. In the following example MATCHES is
used to look for patterns in a variable named "State" that appear to
be New Jersey. This matching pattern will successfully identify
"NJ" "N J" "n.J." "new JerSey".
IF State MATCHES 'N (ew|.)01 @ J (ersey|.)01',
SET State = New Jersey