I would like to find two means of a field called close_diff.
close_diff has some missing values.
One mean (mean_ca_close_diff) is conditional on incident_with_ca=1 and action (character field) not equal to missing.
The other (mean_noca_close_diff) mean is conditional on incident_with_ca=1 and action (character field) equal to missing.
The two means calculated using the code below are the same, however, they shouldn't be.
Any idea how to fix this?
proc sql;
create table EE_1 as
select *,
case when (incident_with_ca=1 and action ne "")
then mean(close_diff) else . end as mean_ca_close_diff,
case when (incident_with_ca=1 and action = "")
then mean(close_diff) else . end as mean_noca_close_diff
from EE
group by INJURY_YEAR
order by EHS_ID
;
quit;
Thank you.
proc sql;
create table EE_1 as
select *,
mean(case
when incident_with_ca=1 and action ne ""
then close_diff else .
end) as mean_ca_close_diff,
mean(case
when incident_with_ca=1 and action = ""
then close_diff else .
end) as mean_noca_close_diff
from EE
group by INJURY_YEAR
order by EHS_ID
;
quit;
OK, how should I fix the syntax?
proc sql;
create table EE_1 as
select *,
mean(case
when incident_with_ca=1 and action ne ""
then close_diff else .
end) as mean_ca_close_diff,
mean(case
when incident_with_ca=1 and action = ""
then close_diff else .
end) as mean_noca_close_diff
from EE
group by INJURY_YEAR
order by EHS_ID
;
quit;
Thank you.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.