Hello all
data new X
input RANDOMNO Visit Value X
DATALINESX
1 0 1
1 1 5
1 2 .
1 3 7
1 4 .
1 5 1
2 0 3
2 1 .
2 2 .
2 3 4
2 4 5
2 5 .
3 0 .
3 1 .
3 2 6
3 3 .
3 4 8
3 5 0
X
RUNX
Proc sort data= new X
By RANDOMNO Visit X
Run X
DATA LOCFX
LENGTH DTYPE $15X
RETAIN retain X
SET new X
BY RANDOMNO Visit X
IF FIRST.RANDOMNO and Visit=0 THEN retain=. X
IF Value NE . and Visit^=0 THEN retain=Value X
IF Value=. THEN DO X
VLOCF=retain X
DTYPE='LOCF' X
END X
ELSE VLOCF=Value X
RUN X
REPLACED SEMICOLE WITH X AS SAS ASK TO REMOVE TO DO THIS BEFORE POSTING
----------------------------------------------------------
Above code I am using to do LOCF. it is giving me a correct result for this data. It may be not correct for large data.
Can you confirm that condition I applied is correct.
is this code will work for a large data also.
please suggest if further refinement to this code should be done.
Please do us (and yourself) a favor and post WORKING code.
The communities provide a special window where you post code (simply by copy/pasting), open it with the "little running man" button right next to the one indicated:
This simplified code does what I think you want:
data have;
input RANDOMNO Visit Value;
datalines;
1 0 1
1 1 5
1 2 .
1 3 7
1 4 .
1 5 1
2 0 3
2 1 .
2 2 .
2 3 4
2 4 5
2 5 .
3 0 .
3 1 .
3 2 6
3 3 .
3 4 8
3 5 0
;
proc sort data=have;
by RANDOMNO Visit;
run;
data want;
set have;
by randomno;
length DTYPE $15;
retain vlocf;
if first.RANDOMNO then vlocf = .;
vlocf = coalesce(value,vlocf);
if value = . then DTYPE = "LOCF";
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.