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.
It's a frequency count
Look at PROC FREQ.
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;
Try
proc sql;
create table calls as
select id, count(*) as nbCalls
from myData
group by id;
quit;
I'd actually really like to create a new variable with number of calls... how would I do that?
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;
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.
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.