CH6 - STAT1303A Data Management 6. Restricting Observations...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
STAT1303A Data Management 6. Restricting Observations and Variables 6 Restricting Observations and Variables Occasionally, we do not want to use the whole data and want to restrict the data that are placed into a data set. Especially for a huge data set, we may just want to use some of the available observations in a data set or some of the variables in a data set. In this chapter, we go through some SAS techniques to perform the tasks. 6.1 Restricting Observations 6.1.1 Restricting observations - INFILE options When raw data is read in by the statement INPUT in a Data Step, we can restrict observations based on their relative positions in the raw data. The options OBS and to be read, e.g. OBS=15 will stop reading data after the 15th records. Note that option OBS refers to an absolute observation number, not a relative number of observations. If we want to read records 5 to 15 inclusively, we may restrict the reading by FIRSTOBS=5 and OBS=15. Example 6.1. Restrict reading observations between 5 and 15. * Example 6.1 - FIRSTOBS and OBS in INFILE; data trade; infile &D:\temp\trade.dat& DELIMITER=&,& firstobs=5 obs=15; length country $56.; input country yr import export reexport; run; SAS log reveals that there are 11 observations in the data set trade although there are 63 records in the raw data originally. How about the following statements INFILE? INFILE datalines &rstobs=101; INFILE datalines obs=100; INFILE datalines &rstobs=50 obs=40; INFILE datalines obs=0; Obviously, the above statements INFILE are invalid. HKU STAT1303A (2009-10, Semester 1) 6 ± 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
STAT1303A Data Management 6. Restricting Observations and Variables 6.1.2 Restricting observations - Data set options If data are already in a SAS data set, a statement SET can copy the data to a new data set. To restrict observations in the new data set, FIRSTOBS and OBS can be used as data set options for the original data set. Example 6.2. Restrict the observations by data set options. * Example 6.2 - FIRSTOBS and OBS in data set option; data trade1; set trade (firstobs=6 obs=10); run; In the above example, a new data set TRADE1 is created. This data set contains the observations 6 through 10 of the data set TRADE. 6.1.3 Data set options Data set options specify actions that apply to the SAS data set with which they appear. Functions include 1. selecting observations for processing by relative positions 2. renaming variables 3. dropping/keeping variables from processing or output and so on.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 05/04/2011.

Page1 / 13

CH6 - STAT1303A Data Management 6. Restricting Observations...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online