DATA Step, Macro, Functions and more

After using the LOCF imputation method

Reply
Occasional Contributor
Posts: 15

After using the LOCF imputation method

Hi how to do locf in this way.

data val1;

input visit $10. value ;

cards;

Week 2 1.5

Week 4 2.3

Week 8 3.2

run;

how to get this output. 

VISIT VALUE

Week 2 1.5

Week 4 2.3

Week 6 2.3

Week 8 3.2

Week 10 3.2

Week 12 3.2

Super User
Super User
Posts: 9,400

Re: After using the LOCF imputation method

Occasional Contributor
Posts: 15

Re: After using the LOCF imputation method

it's not working

Super User
Posts: 9,870

Re: After using the LOCF imputation method


@teja5959 wrote:

it's not working


This is an extremely unhelpful statement. You'd be pissed if @RW9 just answered "It's working", and nothing else, eh?

 

So post your code and your log, and where the result differs from your expectations, so we can test what's "not working".

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 10,681

Re: After using the LOCF imputation method

data val1;
input visit & $10. value ;
cards;
Week 2   1.5
Week 4   2.3
Week 8   3.2
;
run;
data want;
 merge val1 val1(firstobs=2 keep=visit rename=(visit=_visit)) end=last;
 array x{6} $32 _temporary_ ('Week 2' 'Week 4' 'Week 6' 'Week 8' 'Week 10' 'Week 12');
 output;
 do i=whichc(visit,of x{*})+1 to ifn(last,6,whichc(_visit,of x{*})-1);
   visit=x{i};output;
 end;
 drop i _visit;
run;

proc print;run;
Ask a Question
Discussion stats
  • 4 replies
  • 76 views
  • 0 likes
  • 4 in conversation