BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

Hi Arthur, my problem is more complex than that simple example, but this example give you an idea what I wwant to achieve.

Read carefully:

The idea is  imputed only the missing value of the last visits with LOCF, the missing intermediate visits remaining missing, and the carried baseline (i.e week2) if it is missing remaining missing.

In Bold face I show the visits need to be imputed with LOCF

data new;

input subjid week value;

datalines;

1  Baseline 10

1 Week2   12

1 week8  14

1 week12 16

2 baseline 12

2 week2   4

2 week8  14

3 Baseline 13

3 week4  5

3 week12   2

4 baseline 1

4 week2   3

5 Baseline 3

5 Week2  5

5 week12 6

run;

and I am looking for the want dataset:

1  Baseline 10

1 Week2   12

1 week8  14

1 week12 16

2 baseline 12

2 week2   4

2 week8  14

2 week12 14

3 Baseline 13

3 week4  5

3 week12   2

4 baseline 1

4 week2   3

4 week4   3

4 week8  3

4 week12 3


5 Baseline 3

5 Week2  5

5 week12 6

It is is a not easy problem I think, because you need to consider all the possible variations always keeepen imputed the last visits, and not the missing intermediate visisits, and the missing visits follow baseline.

I hope it is more clear now.

Thnaks a lot.

V

and the visit following

data_null__
Jade | Level 19

If you code DAY in a logical way so that it orders the visits chronologically the program is easier.

data new;
   length subjid $8 day 8 value 8;
  
input subjid day value @@;
   datalines;
1  0 10  1  2 12  1  4 14  1  8 16  1  12 12
2  0 10  2  2 12  2  4 10 
3  0 10  3  2  3  3  8  4 
4  0 10  4  8  4
;;;;
   run;
data classdata;
   do day=4,8,12;
    
output;
    
end;
  
run;
proc summary nway data=new classdata=classdata order=internal;
   by subjid;
   class day;
   output out=new2(drop=_freq_ _type_) idgroup(out(_all_)=);
   run;
data new3;
   update new2(obs=0) new2;
   by subjid;
   output;
  
if day eq 0 then call missing(of _all_);
   run;
Ksharp
Super User

If I understand what you mean.

data new;
   length subjid $8 day $10 value 8;
   input subjid day value;
   datalines;
1  baseline 10
1  week2    12
1  week4    14
1  week8    16
1  week12   12
2  baseline 10
2  week4    10
2  week8    10
3  baseline 10
3  week2     3
3  week8     4
4  baseline 10
4  week8     4
;;;;
   run;
data want;
 merge new new(firstobs=2 keep=day rename=( day=_day));
 array a{4} $ _temporary_ ('week2' 'week4' 'week8' 'week12');
 output;
 if day =: 'week' then do; 
           end=whichc(_day,of a{*});
           do i=whichc(day,of a{*})+1 to ifn(end=0,dim(a),end-1);
             day=a{i};output; 
           end;
 end;
run;

Ksharp

Haikuo
Onyx | Level 15

Elegant! Like it! Use 'merge' instead of 'set' to save some typing, array() to eliminate format, colon modifier to skip the baseline and which() to identify the position. You 've got lots of mileage in this very brief code.

Haikuo

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 19 replies
  • 5059 views
  • 7 likes
  • 5 in conversation