BookmarkSubscribeRSS Feed
Mgarret
Obsidian | Level 7

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_SurveyS1S2S3S4S5Points_ PossibleTotal_ points
45451.00.01.01.00.05.03.0
9990.01.0..1.03.02.0
784.0.50.01.00.04.01.5
8520.5.1.0..2.01.5

Thanks!!!

3 REPLIES 3
Reeza
Super User

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;

art297
Opal | Level 21

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;

Astounding
PROC Star

Perhaps even:

points_possible = n(of S:);

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1417 views
  • 0 likes
  • 4 in conversation