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
Onyx | Level 15

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
Onyx | Level 15
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);

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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