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!!!
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;
data test3;
merge test1 test2;
by id;
if first.id then count=0;
if svcdate<admdate then count+1;
run;
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: