Chapter 6. Restricting observations and variables

Chapter 6. Restricting observations and variables - 1...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Restricting observations and variables 2 ¡ Restricting observations ¡ Restricting variables ¡ A data verification example 3 Selecting part of the data ¡ There may be occasions where you want to restrict the data that are placed into a data set ¢ You do not want to use the whole data ¡ We may just want to use ¢ Some of the available observations in a data set ¢ Some of the variables in a data set 4 Restricting observations – INFILE options ¡ When raw data is read in by INPUT statement in a Data Step, we can restrict observations based on their relative positions in the raw data ¡ The OBS and FIRSTOBS options in the INFILE statement do the job ¡ FIRSTOBS specifies the first observation to be read ¢ FIRSTOBS = 5 will skip the first the first 4 records ¡ OBS specifies the LAST observation to be read ¢ OBS=15 will stop reading data after the 15 th records ¢ OBS refer to an absolute observation number, not a relative number of observations 5 ¡ Reads record 5 to 15 inclusively, as restricted by FIRSTOBS=5 and OBS=15 * Example 6.1 - FIRSTOBS and OBS in INFILE; data trade; infile 'c:\temp\trade.dat' DELIMITER=',' firstobs=5 obs=15; length country $56.; input country yr import export reexport; run; 6 ¡ 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 INFILE statements? ¢ INFILE datalines firstobs=101; ¢ INFILE datalines obs=100; ¢ INFILE datalines firstobs=50 obs=40; ¢ INFILE datalines obs=0; 7 Restricting observations – Data set options ¡ If data are already in a SAS data set, a SET statement 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 ¡ Data set options for data set trade1 is used * Example 6.2 - FIRSTOBS and OBS in data set option; data trade1; set trade (firstobs=6 obs=10); run; 8 Data set options ¡ Data set options specifies actions that apply to the SAS data set with which they appear. ¡ Functions include ¢ Selecting observations for processing by relative positions ¢ Renaming variables ¢ Dropping/keeping variables from processing or output ¢ Etc. ¡ Data set options are specified in parentheses after the SAS data set name ¢ Set trade1(firstobs=6 obs=10); ¢ Proc print data=trade1(obs=5); 9 Restricting observations using IF statement ¡ To restrict observations based on the value of one or more variables, SUBSETTING IF statement can be used ¡ Example 6.3 reads in Hong Kong’s trade figures by country. ¢ There is a variable yr indicating the year for the figures. ¢ To select only the observations with year later than 2003, use a subsetting IF statement ¡ IF condition-expression; ¡ This type of IF statement selects a subset of the data for processing based on the evaluated value of the condition expression 10 * Example 6.3 - subsetting IF ; * full data; data trade; infile 'c:\temp\trade.dat' DELIMITER=',';infile 'c:\temp\trade....
View Full Document

This note was uploaded on 02/09/2012 for the course STAT 1301 taught by Professor Smslee during the Spring '08 term at HKU.

Page1 / 37

Chapter 6. Restricting observations and variables - 1...

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

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