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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.