BookmarkSubscribeRSS Feed
jay_bhavsar
Obsidian | Level 7

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.

4 REPLIES 4
Kurt_Bremser
Super User

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:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

Kurt_Bremser
Super User

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;
jay_bhavsar
Obsidian | Level 7
Thank you KurtBremser,
this code is doing good, But one problem is it showing DTYPE = LOCF where locf is not done.
and i dnt want to locf baseline (visit 0) values but in this code its doing that.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 675 views
  • 1 like
  • 2 in conversation