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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 824 views
  • 1 like
  • 2 in conversation