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.