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;

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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