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);
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!
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.