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

Hi SAS experts,

 

Now I have acquired this SAS table:

Screen Shot 2019-06-16 at 5.44.09 PM.png

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
ghosh
Barite | Level 11
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;

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data test3;
	merge test1 test2;
	by id;
	if first.id then count=0;
	if svcdate<admdate then count+1;
run;
--
Paige Miller
ghosh
Barite | Level 11
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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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
  • 2185 views
  • 2 likes
  • 3 in conversation