Replace values with the beginning value

Accepted Solution Solved
Reply
Contributor
Posts: 29
Accepted Solution

Replace values with the beginning value

Hi,

I want to replace values with the beginning values.

 

For example..

 

Data example;

input id year cc;

101 2000 0.2

101 2001 0.3

101 2002 0.4

101 2003 0.3

102 1990 0.5

102 1991 0.3

102 1992 0.6

102 1993 0.4

103 2004 0.3

103 2005 0.4

103 2006 0.6

;

run;

 

After replace the values of cc with the beginning period value of cc by id, I want to have the new data set looking like...

Data want;

input id year cc;

101 2000 0.2

101 2001 0.2

101 2002 0.2

101 2003 0.2

102 1990 0.5

102 1991 0.5

102 1992 0.5

102 1993 0.5

103 2004 0.3

103 2005 0.3

103 2006 0.3

;

run;

 

Thank you!


Accepted Solutions
Solution
‎04-23-2018 10:03 AM
PROC Star
Posts: 1,836

Re: Replace values with the beginning value

[ Edited ]
data want;
set have;
by id; retain _cc; if first.id then _cc=cc; else cc=_cc; run;

retain _cc;

if first.id then  _cc=cc;

else cc=_cc;

run;

 

 

View solution in original post


All Replies
Solution
‎04-23-2018 10:03 AM
PROC Star
Posts: 1,836

Re: Replace values with the beginning value

[ Edited ]
data want;
set have;
by id; retain _cc; if first.id then _cc=cc; else cc=_cc; run;

retain _cc;

if first.id then  _cc=cc;

else cc=_cc;

run;

 

 

Super User
Posts: 10,280

Re: Replace values with the beginning value

Slight change on @novinosrin's take:

data want;
set have (rename=(cc=_cc));
by id;
retain cc;
if first.id then cc=_cc;
drop _cc;
run;

Just to show another possible solution.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 138 views
  • 2 likes
  • 3 in conversation