Writing Observations Explicitly

To override the default way in which the DATA step writes observations to output, you can use an OUTPUT statement in the DATA step. Placing an explicit OUTPUT statement in a DATA step overrides the implicit output at the end of the DATA step. The observations are added to a data set only when the explicit OUTPUT statement is executed.
Syntax, OUTPUT statement:
OUTPUT <SAS-data-set(s)>;
SAS-data-set(s) names the data set or data sets to which the observation is written. All data set names that are specified in the OUTPUT statement must also appear in the DATA statement.
Using an OUTPUT statement without a following data set name causes the current observation to be written to all data sets that are specified in the DATA statement.
With an OUTPUT statement, your program now writes a single observation to output—observation 5. For more information on subsetting IF statements, see Using a Subsetting IF Statement.
data work.usa5; 
  set cert.usa(keep=manager wagerate);
  if _n_=5 then output;
run; 
proc print data=work.usa5; 
run;
Figure 4.5 Single Observation
Single Observation
Suppose your DATA statement contains two data set names, and you include an OUTPUT statement that references only one of the data sets. The DATA step creates both data sets, but only the data set that is specified in the OUTPUT statement contains output. For example, the program below creates two temporary data sets, Empty and Full. The result of this DATA step is that the data set Empty is created but contains no observations, and the data set Full contains all of the observations from Cert.Usa.
data empty full; 
  set cert.usa; 
  output full; 
run;
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.229.159