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 everyone, my problem is a bit complex than that this simple example, but this example give you an idea what I wwant to achieve.

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.

Thnaks.

V.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
I agree with Art on both issues but I will make a guess.
You want to create new observations, by the visit schedule up to week 12 if the LAST DOT observation for a subject is anything other than Baseline.
data new; 
    
length subjid $8 day $10 value 8;
    
input subjid day :$upcase. value;
     * proper representation of time;
    
if day eq: 'B'
        
then time=0;
        
else time=input(substr(day,5),f8.);
     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
6 Baseline 3
;;;;
   run;
data locf;
   set new;
   by subjid;
   output;
  
if last.subjid then do;
     
if time eq 0 then delete;
      if time eq 2 then s=4; else s=time+4;
     
do time=s to 12 by 4;
         day = cats(
'WEEK',time);
         output;
        
end;
     
end;
  
drop s;
   run;

11BASELINE100
21WEEK2122
31WEEK8148
41WEEK121612
52BASELINE120
62WEEK242
72WEEK8148
82WEEK121412
93BASELINE130
103WEEK454
113WEEK12212
124BASELINE10
134WEEK232
144WEEK434
154WEEK838
164WEEK12312
175BASELINE30
185WEEK252
195WEEK12612
206BASELINE30

I forgot to create DAY for the LOCF obs.

View solution in original post

8 REPLIES 8
art297
Opal | Level 21

V.,

The goal of the forum is not to serve as free programmers but, rather, to help people learn the language so they can get to a level where they, too, can help new users.

I think you already have enough examples to at least try to solve this on your own.  If you run into a problem, post the code that you tried and explain where you want it to perform differently.

michtka
Fluorite | Level 6

Sorry, but  I am disagree, a forum is to learn from thisn, a problem generate new ideas.

The above example constitute the real problem, the above problem is the one  I want to achieve...is not fair saying I have enough examples to at least to solve the problem...I am trying to solve this problem from yesterday, is not an easy problem, because if not, it will be solved.

Best,

V.

art297
Opal | Level 21

You haven't stated what the problem is that you are trying to solve.  I think your want dataset doesn't reflect what you really want.

My suggestion would be to define the rules you are trying to achieve and then try write the code that you think should solve that problem.

Many on the forum would be glad to assist at that point.

michtka
Fluorite | Level 6

Thank you Arthur.

Thank you for your help and your interest.

I totally undertood your last email.

I will try next time.

Best,

V.

data_null__
Jade | Level 19
I agree with Art on both issues but I will make a guess.
You want to create new observations, by the visit schedule up to week 12 if the LAST DOT observation for a subject is anything other than Baseline.
data new; 
    
length subjid $8 day $10 value 8;
    
input subjid day :$upcase. value;
     * proper representation of time;
    
if day eq: 'B'
        
then time=0;
        
else time=input(substr(day,5),f8.);
     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
6 Baseline 3
;;;;
   run;
data locf;
   set new;
   by subjid;
   output;
  
if last.subjid then do;
     
if time eq 0 then delete;
      if time eq 2 then s=4; else s=time+4;
     
do time=s to 12 by 4;
         day = cats(
'WEEK',time);
         output;
        
end;
     
end;
  
drop s;
   run;

11BASELINE100
21WEEK2122
31WEEK8148
41WEEK121612
52BASELINE120
62WEEK242
72WEEK8148
82WEEK121412
93BASELINE130
103WEEK454
113WEEK12212
124BASELINE10
134WEEK232
144WEEK434
154WEEK838
164WEEK12312
175BASELINE30
185WEEK252
195WEEK12612
206BASELINE30

I forgot to create DAY for the LOCF obs.

michtka
Fluorite | Level 6

I learn from you guys.

I will try my best next time.

These couple of days has been a nightmare for you (supporting my request) and for me, trying to solve my problem.

Now it has been solved, but not in the way I would like to, because I dont want to upset people.

Thanks again, and hat off to you all.

V.


Haikuo
Onyx | Level 15

Hi V.,

No offense, but I do have a feeling of chasing my 5yr old inside a playground when trying to follow your thread. The forum is for helping each other, not for brain teasing (I don't mind a little bit of that though), so we do have a need to understand your purpose and get to the bottom of it. At the mean time, we expect you to pick it up as much as possible by studying the codes others have offered.  For instance, I mentioned that only one statement added to existing code will meet your need, I haven't seen your response yet: https://communities.sas.com/thread/38368

For this new requirement, my approach will be 2XDOW plus Ksharp's logic :

data new;

input subjid day$. 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

;

data want;

array a{4} $ _temporary_ ('week2' 'week4' 'week8' 'week12');

do until (last.subjid);

  set new;

  by subjid;

end;

if day='week12' then _flag=1;

do until (last.subjid);

set new;

by subjid;

set new (firstobs=2 keep=day rename=( day=_day)) new(obs=1 drop=_all_);

output;

if day =: 'week' and _flag ne 1 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;

end;

drop _:;

run;

proc print;run;

Haikuo

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1033 views
  • 6 likes
  • 4 in conversation