Subsetting and Splitting Datasets how to get rid of ants in the house – SAS Tutorials – LibGuides at Kent State University

Creating a subset that contains only records with a certain how to get rid of ants in the house vinegar value: in this case, your subset will keep the records that meet the criteria how to get rid of ants in the house vinegar you specify. The criteria for keeping an observation is called the inclusion how to get rid of ants in the house vinegar criteria. DATA new-dataset-name (OPTIONS);

Creating a subset that contains only records without a certain how to get rid of ants in the house vinegar value: in this case, your subset will be all of the cases that remain how to get rid of ants in the house vinegar after dropping observations with "disqualifying" values. The "disqualifying" values you specify are called the exclusion criteria. DATA new-dataset-name (OPTIONS);

Conditional logic can get very complex, particularly when the criteria are based on multiple variables and/or multiple values. For example, how would we write the conditional logic for a subset how to get rid of ants in the house vinegar containing only male students, and that live in-state or are at least juniors? In this case, there are three criteria variables: gender, state residency, and class rank. Every subject included in the subset must be male, and in addition to being male, the subject must either a) be an in-state student, or b) be "at least a junior" — i.E., a junior or a senior.

The code required to make this subset is given below. Notice that you can use multiple sets of parentheses to how to get rid of ants in the house vinegar group conditional statements. The parentheses identify the "order of operations" in terms of how the conditional logic statement is read. In this case, it’s mandatory that everyone in the subset be male; after that, they can either be in-state students or at least juniors. DATA sample_subset;

Now let’s say we want to exclude freshmen students that are how to get rid of ants in the house vinegar also in-state students. (that means that our subset will contain all sophomores, all juniors, all seniors, all students with missing class rank values, and out-of-state freshmen.) DATA sample_small;

Now let’s say we want to include only the observations whose how to get rid of ants in the house vinegar math scores fall between 55 and 75. On paper, we can write this condition using the notation $$55 \leq x \leq 75.$$ however, SAS does not recognize this notation. Instead, we must rewrite this as two conditions $$ x \geq 55$$ and $$x \leq 75$$ joined with an AND statement. DATA sample_math;

In this kind of data step, you create two or more datasets at one time based how to get rid of ants in the house vinegar on one whole dataset. This method uses conditional logic with the THEN OUTPUT keywords. It is an extension of the method described above for how to get rid of ants in the house vinegar subsetting data. The basic code to create two datasets is as follows: DATA new-dataset-name-1 (OPTIONS) new-dataset-name-2 (OPTIONS);

Alternatively, you may wish to partition a dataset by separating all how to get rid of ants in the house vinegar cases with a certain criteria into one dataset, and all cases not meeting that criteria into a second how to get rid of ants in the house vinegar dataset. This means that the cases in the two datasets will how to get rid of ants in the house vinegar be mutually exclusive and exhaustive. The basic code to partition a dataset in this manner how to get rid of ants in the house vinegar is: DATA new-dataset-name-1 (OPTIONS) new-dataset-name-2 (OPTIONS);

The general code above only shows the case where a how to get rid of ants in the house vinegar dataset is partitioned into two datasets, but it’s possible to partition a dataset into as many pieces how to get rid of ants in the house vinegar as you wish. In the DATA statement, list the names for each of the new data sets how to get rid of ants in the house vinegar you want to create, separated by spaces. Then in the body of the data step, you’ll write an OUTPUT statement for each dataset name you’ve specified. Let’s illustrate this by splitting the sample dataset into four how to get rid of ants in the house vinegar parts based on class rank, creating one dataset for each class. DATA freshmen sophomores juniors seniors;

Note that this block of code does not take into how to get rid of ants in the house vinegar account the cases where variable rank is missing. That means that the splits in this example were mutually how to get rid of ants in the house vinegar exclusive, but not exhaustive: some of the cases were lost in the split. Example – splitting using IF and ELSE statements with logic based on how to get rid of ants in the house vinegar a numeric condition

Now let’s try to partition the dataset so that all freshmen how to get rid of ants in the house vinegar are in one dataset, and all other cases are put in a second dataset. That means that the second dataset will contain the "not-freshmen"; i.E., sophomores, juniors, seniors, and any cases with a missing value for variable rank. Unlike example 1, this split will create mutually exclusive and exhaustive datasets; that is, none of the original cases will be lost in the how to get rid of ants in the house vinegar split. DATA freshmen not_freshmen;

The ELSE OUTPUT statement can also be used to partition how to get rid of ants in the house vinegar a dataset based on missing and nonmissing values. Recall that missing values are denoted by a period (.) for numeric variables, and by a blank for character variables. Let’s try to partition a dataset into missing and non-missing cases with respect to the variable state, which is a character variable. DATA is_missing not_missing;

To indicate a missing character value, we use an empty set of quotation marks (""). (recall that quotation marks are used in SAS to indicate how to get rid of ants in the house vinegar strings, so having two quotation marks next to each other indicates how to get rid of ants in the house vinegar a blank string.) the syntax IF (state= "") literally says "if state is blank".

RELATED_POSTS