BookmarkSubscribeRSS Feed
dataMart87
Quartz | Level 8

Hi,

 

Can you please give an example or two of when a RETAIN statement is a redundancy and when it is a necessity?

4 REPLIES 4
Reeza
Super User

Its never a redundancy, I would consider it explict versus implicit. 

 

If you use the sum statement, it includes an implicit retain, but expliclity declaring that retain isn't a redundancy in my opinion it's just an explicit declaration so the user knows ahead of time that it will be retained.

 

In all other cases other than implicit the retain statement is required if you want to retain the value across rows. 

 

I'm actually having a hard time understanding the rationale behind question, maybe you can expand on what you're looking for if it's understanding. 

If its for an answer to a test question, it's a bad question IMO. 

PGStats
Opal | Level 21

retain is redundant in :

 

data a;
array a a1 (0);
retain a1;
set sashelp.class end=done;
a1 = a1 + 1;
if done then put a1;
run;
PG
Astounding
PROC Star

All variables that come from a SAS data set are automatically retained.  So RETAIN is redundant when the variable(s) named come from a SAS data set.

 

There are other cases, such as the one PGStats mentioned.

dataMart87
Quartz | Level 8

Are there cases where a variable does not come from a SAS, and a RETAIN is not redundant?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1190 views
  • 0 likes
  • 4 in conversation