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)

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 486 views
  • 0 likes
  • 4 in conversation