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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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;

View solution in original post

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

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;

DJ09
Calcite | Level 5

Thank you so much Linlin for your prompt response! Got the desired results. Thanks again.

robertrao
Quartz | Level 8

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

Linlin
Lapis Lazuli | Level 10

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"

robertrao
Quartz | Level 8

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

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
  • 5 replies
  • 924 views
  • 0 likes
  • 3 in conversation