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

Hi,

 

Identify the subjects with skipped dose

 

ID         Date            Dose    

001     01Jan2014      10      

001     02jan2014       10      

001     03jan2014       10      

001     05jan2014       10      

002     01jan2014       20      

002     02jan2014       20      

002     03jan2014       20      

002     04jan2014       20      

003     02jan2014       10      

003     03jan2014       10      

003     04jan2014       10      

003     06jan2014       10      

 

help me in solving this problem.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Here is one way:

 

data want (drop=counter first_date);
  set have;
  retain first_date;
  by id;
  if not (first.id and last.id);
  if first.id then do;
    counter=0;
    first_date=date;
  end;
  else counter+1;
  if last.id then do;
    if date-first_date ne counter then output;
  end;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post

9 REPLIES 9
art297
Opal | Level 21

Here is one way:

 

data want (drop=counter first_date);
  set have;
  retain first_date;
  by id;
  if not (first.id and last.id);
  if first.id then do;
    counter=0;
    first_date=date;
  end;
  else counter+1;
  if last.id then do;
    if date-first_date ne counter then output;
  end;
run;

Art, CEO, AnalystFinder.com

 

molla
Fluorite | Level 6

Hi  I have done this in following way,correct  me if any thing is wrong

 

proc sort data=test;
	by id;
run;

data test_;
	set test;
	by id;
	x=lag(date);
	format x date9.;

	if first.id then
		x=.;

	if not first.id then
		y=date-x;

	if y ne 1 and y ne . then
		x1='unscheduled visit';
run;

data final;
	set test_;
	where x1='unscheduled visit';
	drop x y x1;
run;
art297
Opal | Level 21

Both your and my code appear to be doing the same thing, but your method required two passes of the data, while mine only required one pass.

 

However, unless your dealing with big data, you probably won't care that it will take twice as long.

 

Regardless, you could have done yours in one pass if rather than using:

 

if y ne 1 and y ne . then x1='unscheduled visit';

simply using

 

if y ne 1 and y ne .;

 

Art, CEO, AnalystFinder.com

molla
Fluorite | Level 6

 what if in this case if we need to find the unscheduled visits?

001     01jan2012      10

001     08jan2012       20

001     20jan2012       30

001     27jan2012       40

001     02jan2012       99

001     03jan2012       99

002     02jan2012      10

002     05jan2012      20

002     03jan2012      99

art297
Opal | Level 21

I presume that you mean how do you identify the skipped dossages. Regardless, if I were you I'd wouldn't ask it in this thread but, rather, submit the question as a new thread/question. You will likely get more responses if people have a chance to be recognized as the solution provider.

 

Art, CEO, AnalystFinder.com

 

Astounding
PROC Star

Does skipped mean they missed a day? 

 

If the first dose is January 2, does that mean that they skipped January 1?

 

Here's one possibility:

 

data want;

set have;

by id;

days_skipped = dif(date) * (first.id=0);

run;

 

It assumes that your data is already sorted by ID, and that your DATE variable contains valid SAS dates.

molla
Fluorite | Level 6

cud u pls explain me what does the following statement do

days_skipped = dif(date) * (first.id=0);

art297
Opal | Level 21

dif(date) takes the difference between the value of date and the value of date on the previous record.

 

first.id will equal 1 for the first id and 0 for all other records within that id, so first.id=0 will have a value of 1 for each record except the first.id record where it will have a value of 0.

 

so multiplying the two will product the number of days since the last visit for each record except the first record for each id. The first record for each ID will get a value of 0.

 

Art, CEO, AnalystFinder.com

 

p.s. Have you posted your new question in a new thread yet?

 

molla
Fluorite | Level 6

Yes I have posted

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 9 replies
  • 1524 views
  • 1 like
  • 3 in conversation