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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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