Help using Base SAS procedures

Count the visits

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Count the visits

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.


Accepted Solutions
Solution
‎07-11-2013 10:35 AM
Super Contributor
Posts: 1,636

Re: Count the visits

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


All Replies
Solution
‎07-11-2013 10:35 AM
Super Contributor
Posts: 1,636

Re: Count the visits

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;

Occasional Contributor
Posts: 10

Re: Count the visits

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

Super Contributor
Posts: 1,040

Re: Count the visits

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

Super Contributor
Posts: 1,636

Re: Count the visits

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"

Super Contributor
Posts: 1,040

Re: Count the visits

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 290 views
  • 0 likes
  • 3 in conversation