next up previous
Next: The counter _N_ Up: The logic of the Previous: The logic of the

The OUTPUT statement

The output statement in a DATA step outputs the observation in its current state to the dataset named on the data line (or all datasets on the data line if no one is specified). Consider the example below:

     data first first_positive;
         set crsp.msf(keep=permno date ret);
	 output first;
	 if ret>0 then output first_positive;
     run;

The dataset first contains all observations read from crsp.msf; the dataset first_positive contains those for which the returns were positive.

There are two things to note about output statements. First, every data step contains an implicit output statement. If there is no output statement in a dataset, then the observation is output as-is at the end of the data step. The two data steps below are identical:

     data first;
         set crsp.msf(keep=permno date ret);
	 output first;
     run;

     data first;
         set crsp.msf(keep=permno date ret);
     run;

Second, when there is an explicit output statement in a data step, the implicit output statement is turned off.

     data first first_positive;
         set crsp.msf(keep=permno date ret);
	 if ret>0 then output first_positive;
     run;

If you run this code, the dataset first has zero observations, since (a) there is an explicit output statement in the data step thus turning the implicit output statement off and (b) no output statement references the dataset first.


next up previous
Next: The counter _N_ Up: The logic of the Previous: The logic of the
Andre de Souza 2012-11-19