BookmarkSubscribeRSS Feed
stancemcgraw
Obsidian | Level 7

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.

6 REPLIES 6
Reeza
Super User

It's a frequency count

 

Look at PROC FREQ.

 

 

 

stancemcgraw
Obsidian | Level 7
Would I than have to do a proc freq though for each person's ID?
Reeza
Super User

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;

 

 

PGStats
Opal | Level 21

Try

 

proc sql;
create table calls as
select id, count(*) as nbCalls
from myData
group by id;
quit;
PG
stancemcgraw
Obsidian | Level 7

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

PGStats
Opal | Level 21

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 6 replies
  • 1759 views
  • 0 likes
  • 3 in conversation