When running a data step in SAS, why does the output statement seem to 'stop' the iterating of the set statement?
I need to conditionally output duplicate observations. While I can use a plethora of output statements, I'd like if SAS did it's normal iterating and output just created an additional observation.
1) Does the run
statement in SAS have a built in output
statement? (The way sum statements have a built in retain
)
2) What is happening when I ask SAS to output certain observations - in particular after a set
statement? Will it set all the values until a condition and then only keep the values I request? or does it have some kind of similarities with other statements such as the point=
statement?
3) Is there a similar statement to output
that will continue to set the values from a previous data step and then output an additional observation when requested?
For example:
data test;
do i = 1 to 100;
output;
end;
run;
data test2;
set test;
if _N_ in (4 8 11) then output;
run;
data test3;
set test;
if _N_ in (4 8 11) then output;
output;
run;
test has 100 observations, test2 has 3 observations, and test3 has 103 observations. This make me think that there is some kind of built in output statement for either the run statement, or the data step itself.
output
statement gets an implicitoutput
statement right at the end. Whenever you add a conditional output, like in your tests, the implicitoutput
is removed and you have to consider whether you need to put it back. See v8doc.sas.com/sashtml/lgref/z0194540.htm for more. – Chris Long