DATA Step, Macro, Functions and more

Summing # of dates for one patient

Reply
Contributor
Posts: 24

Summing # of dates for one patient

Hello,

   I have multiple dates for a person making a phone call. I want to sum the number of calls per patient into a different variable (total number of calls per patient), rather than having multiple dates listed with the same person's ID listed multiple times:

 

 

1 AP001 23AUG2014

2 AP002 29APR2013

3 AP002 23OCT2013

4 AP002 01NOV2013

5 AP002 01NOV2013

6 AP002 14AUG2014

7 AP002 05SEP2014

8 AP002 22SEP2014

9 AP002 22JAN2015

10 AP002 06APR2015

11 AP002 13JUL2015

12 AP002 16JUL2015

13 AP003 25MAR2013

14 AP003 11AUG2013 ...etc.

Super User
Posts: 19,815

Re: Summing # of dates for one patient

Posted in reply to stancemcgraw

It's a frequency count

 

Look at PROC FREQ.

 

 

 

Contributor
Posts: 24

Re: Summing # of dates for one patient

Would I than have to do a proc freq though for each person's ID?
Super User
Posts: 19,815

Re: Summing # of dates for one patient

[ Edited ]
Posted in reply to stancemcgraw

No, put the ID in the PROC FREQ, either as a BY or in the Table statement. 

Try either to see which generates the table you're interested in.

 

proc freq data=have noprint;
table id/out=want;
run;

proc print data=want;
run;

 

 

Respected Advisor
Posts: 4,925

Re: Summing # of dates for one patient

Posted in reply to stancemcgraw

Try

 

proc sql;
create table calls as
select id, count(*) as nbCalls
from myData
group by id;
quit;
PG
Contributor
Posts: 24

Re: Summing # of dates for one patient

I'd actually really like to create a new variable with number of calls... how would I do that?

Respected Advisor
Posts: 4,925

Re: Summing # of dates for one patient

Posted in reply to stancemcgraw

You still want the long list of calls? Try this then

 

proc sql;
create table calls as
select *, count(*) as nbCalls
from myData
group by id;
quit;
PG
Ask a Question
Discussion stats
  • 6 replies
  • 351 views
  • 0 likes
  • 3 in conversation