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);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.