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??
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?
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.
@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.
Thanks it worked.
Can you also explain how should change the n(of whoreact[*]) if the participant should be (55-60)
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: