data have;
input ID Sex Injury_Type;
dataline
1 1 1
1 2
1 3
2 2 1
2 3
;
Data want;
input ID Sex Injury_Type;
dataline
1 1 1
1 1 2
1 1 3
2 2 1
2 2 3
;
Thanks
Su
Hello,
That's the LVCF-method (Last Value Carried Forward aka forward filling).
You find dozens of topic-threads on that subject within these communities.
Because your variables are all numeric, you can use PROC EXPAND (SAS/ETS).
data have;
input ID Sex Injury_Type;
datalines;
1 1 1
. 1 2
. 1 3
2 2 1
. 2 3
;
run;
PROC EXPAND data=have out=want(drop=time)
method=STEP EXTRAPOLATE;
convert _NUMERIC_;
run;
/* end of program */
[EDIT] Take care. This way (above) they are all (i.e. all 3 variables) filled. Maybe you just want
convert ID;
statement.
Koen
Hello,
That's the LVCF-method (Last Value Carried Forward aka forward filling).
You find dozens of topic-threads on that subject within these communities.
Because your variables are all numeric, you can use PROC EXPAND (SAS/ETS).
data have;
input ID Sex Injury_Type;
datalines;
1 1 1
. 1 2
. 1 3
2 2 1
. 2 3
;
run;
PROC EXPAND data=have out=want(drop=time)
method=STEP EXTRAPOLATE;
convert _NUMERIC_;
run;
/* end of program */
[EDIT] Take care. This way (above) they are all (i.e. all 3 variables) filled. Maybe you just want
convert ID;
statement.
Koen
Alternatively you may try
data have;
input ID Sex Injury_Type;
datalines;
1 1 1
. 1 2
. 1 3
2 2 1
. 2 3
;
run;
data want;
set have(rename=(id=_id));
by sex Injury_Type notsorted;
retain id;
if first.sex then id=.;
if _id ne . then id=_id;
run;
data have;
input ID Sex Injury_Type;
datalines;
1 1 1
. 1 2
. 1 3
2 2 1
. 2 3
;
run;
data want;
set have;
if ID then _iorc_ = ID;
else ID = _iorc_;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.