🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-16-2019 05:48 PM
(2747 views)
Hi SAS experts,
Now I have acquired this SAS table:
I want to count the number of visits for each ID. If the service_date(svcdate) is smaller than admission_date(admdate), then the number of visits should increase by 1. How do I accomplish this?
My previous codes to get this table are as follow:
data test1;
input svcdate : mmddyy10. id @@;
format svcdate mmddyy10.;
cards;
04/11/2008 1 06/29/2008 1 07/22/2008 1
03/05/2008 2 11/15/2008 2 01/04/2008 2
01/07/2008 3 04/05/2008 3 06/06/2008 3
;
run;
data test2;
input admdate : mmddyy10. id @@;
format admdate mmddyy10.;
cards;
05/01/2008 1
08/01/2008 2
07/01/2008 3
;
run;
proc sort data=test1;
by id svcdate;
run;
proc sort data=test2;
by id admdate;
run;
data test3;
merge test1 test2;
by id;
run;
proc print data=test3; run;
Thans!!!
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test3;
merge test1 test2;
by id;
visits=svcdate<admdate;
run;
proc summary nway data=test3;
class id;
var visits;
output out=totalvisits (drop=_:)
sum=
;
run;
proc print label;
id id;
var visits;
label visits="# of Visits";
run;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test3;
merge test1 test2;
by id;
if first.id then count=0;
if svcdate<admdate then count+1;
run;
--
Paige Miller
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data test3;
merge test1 test2;
by id;
visits=svcdate<admdate;
run;
proc summary nway data=test3;
class id;
var visits;
output out=totalvisits (drop=_:)
sum=
;
run;
proc print label;
id id;
var visits;
label visits="# of Visits";
run;