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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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