You might use code like this when you want to copy a dataset from the temporary library to a permanent library or vice versa. If you do not want to make a copy of a dataset, and instead wish to modify an existing dataset, then you can simply use the same dataset name in the DATA statement and in in the SET statement.
However, you should be aware that this will permanently overwrite the existing dataset. That is, if you use the same names, then SAS will overwrite the existing dataset with the new dataset you are creating. Data step options generally perform variable-level actions, like renaming or dropping variables from a dataset.
Options usually appear in parentheses right after the name s of a dataset that is referenced in the DATA statement or in the SET statement.
These two options can accomplish the same thing, but in a given situation one will likely be easier than another. If you only want to remove a couple of variables from a dataset, then using a DROP option would be easier than specifying all the variables to stay in a KEEP option.
Conversely, if you only want to keep a couple of variables in the dataset then using a KEEP option would be easier than specifying all the variables to remove in a DROP option. Suppose we want to create a new dataset with a variable BMI computed from the existing variables height and weight.
Suppose that we also don't want the height and weight variables to be carried over into the new dataset. Let's say that we want to make a copy of our dataset, but only keep the character variables and the ID variable , ids. Its general form is:. You can rename more than one variable within the parentheses as long as each pair of old and new variable is separated by a space.
Data step options provide SAS with additional instructions on how to read or write the dataset you name. They are generally attached to an output dataset one that SAS is going to create , but they can also be attached to an input dataset one that SAS is going to read, like when a SET statement is used. We have covered some of the most common data step options here.
Search this Guide Search. Renaming a variable A variable column name can be renamed with the rename option:. See also merge , update and merge join in data step. SAS: Interaction between macros and data steps with execute, symget and symput. SAS Programming Language. Specifying an Oracle schema in a data step set statement. Convert between data types. If you need to use specific libraries frequently, declare them in the autoexec. Consider the following example. The output of a DATA step is stored into the data set specified.
The following example creates two data sets WORK. The gov1 and gov2 in the WORK library are identical except that the egov1 does not include variables state and msa , and has a variable id whose name is changed from respid. If a data set name is omitted, the computer will automatically name each successive data set as WORK. These data sets, however, may consume computing resources and slow down the access and response speed.
How to select and delete some observations in a data set? The IF THEN statement can do that for you.. The following example retrieves observations from a data set jeeshim. This statement removes observations that meet the conditions provided. You may also select observations by specifying a range of record numbers. The first observations are saved into WORK. You may try the WHERE statement, which selects observations from an existing data set without physically removing observations that do not meet a condition.
In a procedure step, this statement limits observations used in analysis. The following example reads observations from jeeshim.
0コメント