


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. 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. These two options can accomplish the same thing, but in a given situation one will likely be easier than another. DROP tells SAS to remove only the listed variables from the dataset all other variables are kept.KEEP tells SAS to keep only the listed variables all other variables are removed from the dataset.In the data step, DROP and KEEP are used to "throw out" certain variables from your dataset: That is, if you use the same names, then SAS will overwrite the existing dataset with the new dataset you are creating. However, you should be aware that this will permanently overwrite the existing dataset. 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.
Sas code#
You might use code like this when you want to copy a dataset from the temporary library to a permanent library or vice versa. For example, the program DATA new_sample Ĭreates a new temporary dataset called new_sample that is a clone of the already existing dataset called sample. (It is strongly recommended that you do not alter your original data files.) Copying or cloning an existing datasetĪ data step containing only the SET statement will create an exact copy of the dataset. This allows you to create new variables or recode existing variables without permanently changing the original data. The statements above tell SAS to create a new dataset ( New-Dataset-Name) that is an exact copy of an existing SAS dataset ( Existing-Dataset-Name). In general the code will follow this form: DATA New-Dataset-Name (OPTIONS) When you need to copy or modify an existing dataset, use the SET statement in the data step.
