By Statement

Contents Index


Used in conjunction with a SAS procedure, the by statement specifies variables in the data set which are used to break the data set into groups for processing by the procedure. The data set is assumed to be sorted in ascending order according to the by variables, but this can be overridden through the use of the descending modifier. The invocation

proc means 
	data=junk;
	var z;
	by x descending y;
run;

produces a separate analysis of the z values in the data set junk in each group determined by a specified x and y value. The groupings will appear in order of ascending x values, and within each x value in order of descending y values.

If the modifier notsorted appears in a by statement, processing proceeds for each group of consecutive data having the same value(s) of the by variable(s). This may produce many more groups than desired if the data is not sorted. Example:

by x notsorted;

The by statement also causes to temporary logical variables first. and last. to be created. These variables evaluate to true when the current data card corresponds to the first or last card of the by group. Example:

data final;
set first;
by id;
if first.id;
run;

The data set final will contain only the first entry of each id group.

For further information see the SAS Language Reference.


Contents Index

Copyright © 1997 by Jerry Alan Veeh. All rights reserved.