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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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