BookmarkSubscribeRSS Feed
deleted_user
Not applicable
what is the difference using of keep and drop statement in DATASET,SET statement and PROC step ?please explain me.Thanks in advance.
4 REPLIES 4
deleted_user
Not applicable
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
DanielSantos
Barite | Level 11
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
PQK
Calcite | Level 5 PQK
Calcite | Level 5
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 857 views
  • 0 likes
  • 4 in conversation