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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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