DATA Step, Macro, Functions and more

keep and drop

Reply
N/A
Posts: 0

keep and drop

what is the difference using of keep and drop statement in DATASET,SET statement and PROC step ?please explain me.Thanks in advance.
N/A
Posts: 0

Re: keep and drop

Posted in reply to deleted_user
KEEP and DROP are complementary statements. I tend to use the one that has the shorter variable list. If you read 10 variables and want to keep 9, then DROP the 1 variable not required. However, if you only want to keep 2 of them it makes sense to code those 2 on a KEEP statement rather than listing the other 8 on a DROP.
Super Contributor
Super Contributor
Posts: 3,174

Re: keep and drop

Posted in reply to deleted_user
Also, you want to review the OPTIONS DKRICOND= and DKROCOND= parameters.

And, consider the use of the DROP= and KEEP= SAS dataset options.

Lastly, DROP overrides KEEP when specifying a named SAS variable or variable prefix/stem.

Scott Barry
SBBWorks, Inc.
Super Contributor
Posts: 474

Re: keep and drop

From my knowledge there is no actual differences between KEEP/DROP used from a Datastep or SAS Procedure. So a KEEP/DROP statement will do and work pretty much the same if used from within a Datastep or SAS Procedure.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Contributor PQK
Contributor
Posts: 21

Re: keep and drop

Posted in reply to DanielSantos
I just discovered an important (and potentially frustrating--as it was in my case) difference between DROP and KEEP.

When including a DROP or KEEP statement within the DATA statement (and before the INPUT statement), the KEEP statement prevents you from creating custom variables in the INFILE statement.

For example, I was trying to extract a 7-character numeric string from the end of an existing variable and put it into a new variable.

Through the process of elimination I determined that the KEEP statement disallows the creation of custom variables, while the DROP statement does not interfere with the addition of new variables.

The default for imported CSV files in EG4.3 appears to be the KEEP statement, so if you want to add custom variables within the preexisting generated EG4.3 code, you need to switch this KEEP statement to the DROP statement (and switch your variables accordingly).

I would be interesting to hear if someone has an easier way to work around this difference.

PQK
Ask a Question
Discussion stats
  • 4 replies
  • 183 views
  • 0 likes
  • 4 in conversation