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

hello. i made data set, counting patient's visiting number(except admission) before they got surgery.

 

raw data is here.

 

id date admission_YN surgery_YN

1 2002/01/28 0 0
1 2002/02/15 0 0
1 2002/04/06 1 0

1 2002/05/05 0 0
1 2002/06/07 1 1
1 2002/08/10 0 0
1 2003/01/12 0 0
2 2003/01/15 0 0
2 2003/02/10 1 0
2 2003/03/10  1 1
2 2003/04/08 0 0

 

and with this code, i made a data set. but i can't exclude(=jump over) visiting for admission.

 

proc sort data=have;
by id date;
run;
data want;
retain had_surgery;
set have;
by Id date;
if first.id then
do;
had_surgery = 0;
count = 0;
end;
if surgery_yn = 0 and had_surgery = 0 then count+1;
else if surgery_yn = 1 then
do;
had_surgery = 1;
count=0 ;
end;
run;

 

id date admission_YN surgery_YN count

1 2002/01/28 0 0 1
1 2002/02/15 0 0 2
1 2002/04/06 1 0 3

1 2002/05/05 0 0 4
1 2002/06/07 1 1 0
1 2002/08/10 0 0 0
1 2003/01/12 0 0 0
2 2003/01/15 0 0 1
2 2003/02/10 1 0 2
2 2003/03/10  1 1 0
2 2003/04/08 0 0 0

 

i want make data set like this. how can i jump over admission event?

 

id date admission_YN surgery_YN count

1 2002/01/28 0 0 1
1 2002/02/15 0 0 2
1 2002/04/06 12

1 2002/05/05 0 0 3
1 2002/06/07 1 1 0
1 2002/08/10 0 0 0
1 2003/01/12 0 0 0
2 2003/01/15 0 0 1
2 2003/02/10 1 0 1
2 2003/03/10 1 1 0
2 2003/04/08 0 0 0

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if surgery_yn = 0 and had_surgery = 0 and admission_yn=0 then count+1;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
if surgery_yn = 0 and had_surgery = 0 and admission_yn=0 then count+1;
--
Paige Miller
novinosrin
Tourmaline | Level 20
data have;
input id date : yymmdd10. surgery_YN;
format date yymmdd10.;
cards;
1 2002/01/28 0 0
1 2002/02/15 0 0
1 2002/04/06 1 0
1 2002/05/05 0 0
1 2002/06/07 0 1
1 2002/08/10 0 0
1 2003/01/12 0 0
2 2003/01/15 0 0
2 2003/02/10 1 0
2 2003/03/10 0 1
2 2003/04/08 0 0
;





data want;
set have;
by id date;
if first.id then do;f=0;count=0;end;
f+surgery_YN;
if f<1 then count+1;
if lag(surgery_YN)=1 and surgery_YN=0 then count=0;
drop f;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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