BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cy_th
Fluorite | Level 6

D5.pngD6.png

I am trying some very basic SAS programs. It calculates the average of scores obtained in 4 subjects. One of the scores is missing in an observation and hence the average is not getting calculated. How do I overcome this?

I have attached a screenshot of my code and output. It is extremely simple. Kindly help.

data scores;
infile "/folders/myfolders/71442_example/scores.txt";
input gender $ english 
math 
history 
science;
avg = (english + math + history +science)/4;
run;

proc print data=scores;
run;

This is the data:

M 80 82 85 88

F 94 92 88 96

M 96 88 89 92

F 95 . 92 92

1 ACCEPTED SOLUTION

Accepted Solutions
1 REPLY 1
Kurt_Bremser
Super User

Instead of

(english + math + history +science)

use

sum(english,math,history,science)

and you will only get a missing value if all values are missing.

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

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 910 views
  • 1 like
  • 2 in conversation