Hi all—
I’m trying to use base SAS to count points possible and points earned. When counting points possible missing values do not count. I have been trying to use the count function. Is that correct? Your help is appreciated.
data want (keep=S1 S2 S3 S4 S5);
set have;
Points_ Possible=count(S1, S2, S3, S4 ,S5); Not
Total_ points=sum(S1, S2, S3, S4 ,S5);
run;
What I need:
Id_Survey | S1 | S2 | S3 | S4 | S5 | Points_ Possible | Total_ points |
4545 | 1.0 | 0.0 | 1.0 | 1.0 | 0.0 | 5.0 | 3.0 |
999 | 0.0 | 1.0 | . | . | 1.0 | 3.0 | 2.0 |
784 | . | 0.5 | 0.0 | 1.0 | 0.0 | 4.0 | 1.5 |
852 | 0.5 | . | 1.0 | . | . | 2.0 | 1.5 |
Thanks!!!
Use the n() function
data want (keep=S1 S2 S3 S4 S5 Points_possible total_points);
set have;
Points_ Possible=n(S1, S2, S3, S4 ,S5);
Total_ points=sum(S1, S2, S3, S4 ,S5);
run;
There are a number of ways to do what you want. I prefer something like the following, as it is easy to modify for different surveys:
data have;
input Id_Survey S1 S2 S3 S4 S5;
cards;
4545 1.0 0.0 1.0 1.0 0.0 5.0 3.0
999 0.0 1.0 . . 1.0 3.0 2.0
784 . 0.5 0.0 1.0 0.0 4.0 1.5
852 0.5 . 1.0 . . 2.0 1.5
;
data want;
set have;
array s(*) s:;
Points_Possible=dim(s)-nmiss(of S:);
Total_points=sum(of S:);
run;
Perhaps even:
points_possible = n(of S:);
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!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.