BookmarkSubscribeRSS Feed
pacman94
Calcite | Level 5

I would like to average all values ONLY if all values are filled out. 0 doesn't mean missing. if the values are not filled out, then they should be blank

IDvalue1value2value3value4
18226
25 010
33436
36206

 

Want

IDvalue1value2value3value4average_values
182264.5
25 010 
334364
362063.5

 

This is what i have so far

data test; set raw;

average_values = MEAN(value1, value2, value3, value4);

run;

 

it still calculates all average 

4 REPLIES 4
LeonidBatkhan
Lapis Lazuli | Level 10

Hi pacman94,

 

You can achieve this with the following code:

options missing=' ';

data test;
    set raw;
   average_values = (value1+value2+value3+value4) / 4;
run;

 

Hope this helps.

yabwon
Amethyst | Level 16

Only disadvantage is this:

NOTE: Missing values were generated as a result of performing an
      operation on missing values.

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Amethyst | Level 16
data test; 
  set raw;
  if nmiss(value1, value2, value3, value4) then average_values =.;
  else average_values = MEAN(value1, value2, value3, value4);
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



novinosrin
Tourmaline | Level 20

or just-

  if not nmiss(value1, value2, value3, value4) then 
 average_values = MEAN(value1, value2, value3, value4);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1070 views
  • 5 likes
  • 4 in conversation