BookmarkSubscribeRSS Feed
knargis160
Calcite | Level 5

Hi 

I have dataset with 

 who_reacted_1   who_reacted_2----so on

 1.              5556                   5555       

 I want to calculate total number of who_reacted-like for first it should be 2

who_reacted_1 they all are character.

data testing_nreact; set redcap;
array whoreact(*) who_reacted_1-who_reacted_40;
  do i=1 to 40;
  n_reaction=0;
  sum_nreactions =sum(of whoreact[*]);
  end;
run;

Can anyone help with code??

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I cannot understand this sentence at all: "I want to calculate total number of who_reacted-like for first it should be 2 who_reacted_1 they all are character."

 

Can you please explain further? And maybe provide an example with more than one data point?

--
Paige Miller
jklaverstijn
Rhodochrosite | Level 12

If you mean you want to count the number of reactions instead of their sum, replace this lien

 

sum_nreactions =sum(of whoreact[*]);

with

num_reactions =n(of whoreact[*]);

The N() function counts the number of non-missing values.

 

Hope this helps,

- Jan.

 

ballardw
Super User

@jklaverstijn wrote:

If you mean you want to count the number of reactions instead of their sum, replace this lien

 

sum_nreactions =sum(of whoreact[*]);

with

num_reactions =n(of whoreact[*]);

The N() function counts the number of non-missing values.

 

Hope this helps,

- Jan.

 


AND doing either of Sum(of whoreact[*]) or N(of whoreact[*]) in a loop is completely unneeded. Unless you really want to sum/count the same things 40 times to get the one result.

knargis160
Calcite | Level 5

Thanks it worked.

Can you also explain how should change the n(of whoreact[*]) if the participant should be (55-60)

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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