Hi all.
My data looks like the one below.
Resp = name of person
Proc_done = x, if procedure is accomplished .
I would like to add the x's for each person.
Resp Proc_done Proc_done_2 Proc_done_3
A x x
A x
B x
C x x
C x x x
D x x
E x
E x x
F x
G x x x
The output should look like:
Resp nProc_done
A 3
B 1
C 6
D 2
E 3
F 1
G 3
Thank you in advance.
Edit your post using a self-contained data step using datalines, instead of forcing me to convert your cut-and-paste job into a data step.
I'll then answer your question.
Hi @yoyong555
PLEASE post your input data as code to create a have-data set, so we have something to work on!
As always, there are several ways of doing things in SAS, here is a Proc SQL solution and a Data Step solution. The output is the same, but the data step requires the input to be sorted on Resp, this is not necessary with proc sql.
proc sql;
create table want as
select
Resp,
sum(sum(Proc_done='x',Proc_done_2='x',Proc_done_3='x')) as nProc_done
from have
group by Resp;
quit;
data want2(keep=Resp nProc_done); set have; by resp;
retain nProc_done;
if first.Resp then nProc_done = 0;
nProc_done = sum(nProc_done,Proc_done='x',Proc_done_2='x',Proc_done_3='x');
if last.Resp then output;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.