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
| ID | value1 | value2 | value3 | value4 |
| 1 | 8 | 2 | 2 | 6 |
| 2 | 5 | 0 | 10 | |
| 3 | 3 | 4 | 3 | 6 |
| 3 | 6 | 2 | 0 | 6 |
Want
| ID | value1 | value2 | value3 | value4 | average_values |
| 1 | 8 | 2 | 2 | 6 | 4.5 |
| 2 | 5 | 0 | 10 | ||
| 3 | 3 | 4 | 3 | 6 | 4 |
| 3 | 6 | 2 | 0 | 6 | 3.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
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.
Only disadvantage is this:
NOTE: Missing values were generated as a result of performing an
operation on missing values.
Bart
data test;
set raw;
if nmiss(value1, value2, value3, value4) then average_values =.;
else average_values = MEAN(value1, value2, value3, value4);
run;
or just-
if not nmiss(value1, value2, value3, value4) then
average_values = MEAN(value1, value2, value3, value4);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.