Wednesday, 19 March 2014

SAS_DropKeepRename

Q)Explain the difference between drop,keep,rename statements and data set options.

Drop, Keep,Rename Statement Vs Drop,Keep,Rename Data Step Option

The DROP, KEEP, and RENAME statements or the DROP=, KEEP=, and RENAME= data set options control which variables are processed or output during the DATA step.

Statements

Data Set Options

apply to output data sets only.

apply to output or input data sets.

affect all output data sets.

affect individual data sets.

can be used in DATA steps only.

can be used in DATA steps and PROC steps.

can appear anywhere in DATA steps.

must immediately follow the name of each data set to which they apply.

·         If the action applies to output data sets, you can use either a statement or a data set option in the output data set but for input data sets, only data step option can be used.

·         if you use the DROP, KEEP, or RENAME statement OR Drop,Keep,Rename data step option on output data step:
the action always occurs just before the variables are written to the output data set.
(If variables are not written to the output data set but require any processing Then use drop statements or drop data step option on output dataset.)

·         If the drop,keep,rename option is used on an input data set, the variable is dropped, kept, or renamed before it is read into the program data vector.
(If variables are not written to the output data set and they do not require any processing, using drop on an input data set option to exclude them from the DATA step is more efficient.)

·         If you want to rename a variable before processing it in a DATA step, you must use the RENAME= data set option in the input data set.
(If you want the old name while data step processing and new name in output dataset, then Rename=data set option on output dataset OR Rename statement can be used.)

Q) What is the difference between using drop= data set option in data statement and set statement?
If you don’t want to process certain variables and you do not want them to appear in the new data set, then specify drop= data set option in the set statement.
Whereas If want to process certain variables and do not want them to appear in the new data set, then specify drop= data set option in the data statement.

Q)If you have a data set that contains 100 variables, but you need only five of those, what is the code to force SAS to use only those variable?
Using   KEEP option or statement.

Q)What is the order of application for output data set option, input data set option and SAS statement?
INPUT data set option, SAS statement option and then OUTPUT option.

 

No comments:

Post a Comment