DATA Step, Macro, Functions and more

retain

Accepted Solution Solved
Reply
Regular Contributor
Posts: 234
Accepted Solution

retain

[ Edited ]

Hello,

 

This example code is takne from this paper (https://www.pharmasug.org/proceedings/2013/TF/PharmaSUG-2013-TF12.pdf). I don' think we need to retain ldosdt variable.

 

DATA ds1a (keep=usubjid fdosdt ldosdt);
	set ipadmin;
	by usubjid startdt;
	retain fdosdt ldosdt;

	if first.usubjid then
		fdosdt = startdt;

	if last.usubjid then
		do;
			ldosdt = startdt;
			output;
		end;
run;

I tried to simulate the above with this program.

 

data test;
	input id $ x;
	cards;
a  1
a  2
a  3
;
run;

data want;
	set test;
	by id;
	retain f_;

	if first.id then
		f_=x;

	if last.id then
		do;
			l_=x;
			output;
		end;
run;

 


Accepted Solutions
Solution
‎07-02-2017 02:30 PM
PROC Star
Posts: 7,356

Re: retain

[ Edited ]

You are correct .. you don't have to retain the 2nd variable. Doesn't hurt, but definitely not necessary.

 

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎07-02-2017 02:30 PM
PROC Star
Posts: 7,356

Re: retain

[ Edited ]

You are correct .. you don't have to retain the 2nd variable. Doesn't hurt, but definitely not necessary.

 

Art, CEO, AnalystFinder.com

 

Regular Contributor
Posts: 234

Re: retain

@art297 Thanks, Art.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 153 views
  • 0 likes
  • 2 in conversation