DATA Step, Macro, Functions and more

Keep vs Retain Statement

Reply
Occasional Contributor
Posts: 17

Keep vs Retain Statement

Could someone tell me the difference between Keep and Retain statements for SAS?

 

Thanks!

Contributor
Posts: 42

Re: Keep vs Retain Statement

keeps refers to the variable beeing read or written in the dataset

 

retain stores the value of a variable between observations, it surpresses reseting of the variable

Super User
Posts: 13,531

Re: Keep vs Retain Statement

In addition ot @chrej5am, Keep (and Drop) can be a data set option and used anywhere a dataset is used to restrict the variables used by a procedure. Retain is only valid in a data step.

Super User
Posts: 10,238

Re: Keep vs Retain Statement

Adding to what @chrej5am said, retain works reliably only with newly created variables. Variables that are already present in the input dataset(s) will be overwritten anytime a new observation is read.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 3 replies
  • 2726 views
  • 0 likes
  • 4 in conversation