Hello everyone,
Here is an example where I need help with.
Data have;
input subjid week product;
cards;
101 21 x1
101 22 x1
101 23 x1
101 24 x1
102 19 x1
102 20 x1
102 22 x1
102 23 x1
102 24 x1
;
run;
What I would like to achieve here is to count the weeks to see when each subject stop as the ending period is 24 weeks and it has to be consistent without missing any week or else ignore those weeks where he missed.In the above case its going to be week 19 and 20 for subjid 102 since he missed week 21.So can someone tell me how can I do this? I appreciate any help I get.Thanks in advance.
Data have;
input subjid week product $;
cards;
101 21 x1
101 22 x1
101 23 x1
101 24 x1
102 19 x1
102 20 x1
102 22 x1
102 23 x1
102 24 x1
;
data temp;
set have;
if subjid=lag(subjid) and dif(week)>1 and week ne 24 ;
data want(drop=n);
merge have temp(in=a rename=(week=n));
by subjid;
if a and week<n;
proc print;run;
Data have;
input subjid week product $;
cards;
101 21 x1
101 22 x1
101 23 x1
101 24 x1
102 19 x1
102 20 x1
102 22 x1
102 23 x1
102 24 x1
;
data temp;
set have;
if subjid=lag(subjid) and dif(week)>1 and week ne 24 ;
data want(drop=n);
merge have temp(in=a rename=(week=n));
by subjid;
if a and week<n;
proc print;run;
Thank you so much Linlin for your prompt response! Got the desired results. Thanks again.
I have a couple of questions
if subjid=lag(subjid) and dif(week)>1 and week ne 24 ;
1)why is the weeek 24 not included?
3)In the final dataset obtained we do not have any 101 at all???Why is that info ignored??i was thinking all the info must be included from Have dataset and only the misswing weeks info for a particular patient has to be eliminated
Thanks
HI,
You are right, I think "if subjid=lag(subjid) and dif(week)>1 and week ne 24 " should be "if subjid=lag(subjid) and dif(week)>1 ";
I thought OP wanted
"In the above case its going to be week 19 and 20 for subjid 102 since he missed week 21"
Hi Thanks for the reply.
Also what about the 101's ?????
i was thinking WANT dataset would have 19 and 20 of 102 and also
21-24 of 101 because there are no missing months to eliminate??
How would we get to include those in our final dataset???
Thanks
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.