Subset the records of cars manufactured in a particular continent
Select only the male student records from the class dataset
Identify and list the subjects of a clinical trial whose age is grater then 60
Create sample input datasets
Subset the records using 'where' statement
To subset the observations, we need to specify the record selection condition on the where statement
Create a dataset named males by subsetting the male student records from class dataset
Notice in the log about the number of observations read from the input dataset
With where statement, only those records which meet the specified subset condition will be read into PDV from the input dataset
Create a dataset named females_preteen by subsetting female student records whose age is less than 13 from class dataset
We need to filter the records based on the values present in two different variables: SEX and AGE
We can combine the filter components with an 'and' operator
Create a dataset named cars_mileage by subsetting the cars with mpg_city > 24 or mpg_highway >30 from cars dataset
We ned to filter the records based on teh values present in two different variables: MPG_CITY and MPG_HIGHWAY
As we need to filter the records which meet at least one filter condition, we can combine the filter combponents with an 'or' operator
Subsetting the records with subsetting if statement
When a subsetting if statement is used, SAS continues processing only those observations that meet the condition of the specified expression.
When the specified expression gets evaluated to false, SAS returns the control back to data statement and reads next observation into PDV
AS SAS writes an observation to the output dataset only when a step boundary is encountered, the observations which do not meet the filter
expression never reaches the step boundary in the execution, hence those observations will never be written to the output dataset
Create a dataset named females by subsetting female records using subsetting if statement
Create a dataset named select_sedans by subsetting Sedan cars with a highway mileage greater than 35 using subsetting if statement
Create a dataset named cheap_mileage by subsetting the cars with msrp < 15000 dollars or city mileage greater than 40 using subsetting if statement
Subsetting the records using if ... then output
Output statement in SAS is used for instructing the data step to write the contents of PDV to the output dataset
In this case, we are making use of conditional processing (if then syntax) along with output to subset the observations
With the syntax, 'if (condition is true) then output;' we are instructing SAS to write only those observations to the
output dataset which meet a specific filtering condition
Create a dataset named tall by subsetting the students with height greater than 60 using if ... then output
Subsetting the records using if ... then delete
Delete statement in SAS is used in instructing the data step to delete the contents of PDV and fetch next observation
for processing, in turn the current observation is not written to the output dataset
With the syntax, 'if (condition is true) then delete;' we are instructing SAS to stop writing the specified observations to the
output dataset which meet a specific filtering condition
Create a dataset named short by subsetting the students with height less than 60 using if ... then delete
Notice that as we need student records with height less than 60, we are deleting the records of students whose height is
greater than or equal to 60