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!
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;
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;
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.
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.
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.