SAS Programming

DATA Step, Macro, Functions and more
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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2748 views
  • 2 likes
  • 3 in conversation