Keeping only the observations you want
There are several ways you can let SAS know exactly which observations you want written to a data set. The first example below uses the subsetting
IF statement. The second
example accomplishes the same thing with the DELETE statement.
The subsetting IF statement
IFcondition;- if the condition is true, continue to execute data step
- if the condition is false, stop processing current observation and return to top of data step
- in particular, if the condition is false do not output the current observation being formed in the Program Data Vector (PDV)
Example--only two observations will be output by the data step:
/**************************************************************** Example--only two observations will be output by the data step: ****************************************************************/ data alpha; infile datalines; input a b c; d= c - b; if d > 0; /* output obs only if d > 0 */ datalines; 1 5 10 0 8 7 1 4 6 ; run; proc print; run;Theproc printabove would display the data set "alpha" like this:OBS A B C D 1 1 5 10 5 2 1 4 6 2
The DELETE statement
IF condition THEN DELETE;- if the condition is true then stop processing the current observation and return to the top of the data step
- in particular, if the condition is true, do not output the current observation being formed in the PDV
/*********************************************************************** Example--this data step gives the same result as the data step above: **********************************************************************/ data alpha; infile datalines; input a b c; d= c - b; if d <= 0 then delete; /* do not output obs if d <= 0 */ datalines; 1 5 10 0 8 7 1 4 6 ; run;
Another topic?


