BookmarkSubscribeRSS Feed
yoyong555
Obsidian | Level 7

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.

 

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Like this?

 NBPROC=count(catt(of PROC_DONE:), 'x');

 

ScottBass
Rhodochrosite | Level 12

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.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ErikLund_Jensen
Rhodochrosite | Level 12

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;

 

 

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