I am trying to calculate a sum of several variables using the SUM function. I get different totals when I use a list versus specifying each individual variable in the paraenthesis. What's going on here?
/* 8. Female, Black, Untreated, Non-smoker, Non-diabetic */
/***********************************************************/
else if
gender = 2 and
race_all = 4 and
htn_meds = 2 and
smk_status ne 1 and
ever_told_dm2 ne 1
then do;
ascvd_age = log(age_yrs)*(17.114);
ascvd_tchol = log(tchol_mg)*0.940;
ascvd_hdl = log(hdl_mg)*(-18.920);
/* Interaction - age and HDL */
ascvd_age_x_hdl = log(age_yrs)*log(hdl_mg)*(4.475);
/* Untreated SBP */
ascvd_sbp_notx = log(mean_sbp)*27.820;
/* Interaction - age and UNTREATED SBP */
ascvd_age_x_sbp_notx = log(age_yrs)*log(mean_sbp)*(-6.087);
/* Non-smoker */
ascvd_smk = 0*(0.691);
/* Non-diabetic */
ascvd_ever_told_dm2 = 0*(0.874);
/***********************************************************/
ind_sum_blk_f_wtf = sum(of ascvd_:);
ind_sum_blk_f = sum(ascvd_age, ascvd_tchol, ascvd_hdl, ascvd_age_x_hdl, ascvd_sbp_notx, ascvd_age_x_sbp_notx, ascvd_smk, ascvd_ever_told_dm2);
mean_blk_f = 86.61;
bline_surv_blk_f = 0.9533;
ascvd_score = (1 - bline_surv_blk_f**(exp(ind_sum_blk_f - mean_blk_f)))*100;
end;
ind_sum_blk_f_wtf=102.55228166
ind_sum_blk_f=87.81412573 (this is the correct/desired value)
There must be some other variable that starts with ascvd_ which you are not expecting.
To see it, suggest you add:
put (ascvd_:) (=);
Before the assignment statement.
That should show you all of the variables in the ascvd_: variable list.
The variable
ascvd_score
is in your first list (of ascdv_) but not the second.
Are you suggesting that ascvd_score is being included in the calculation of the sum? How could this be if the SUM function precedes the creation of that variable?
What if the variable is already in the incoming dataset?
You did not provide full working code, but you asked why the two function calls were different. I pointed out the obvious difference that they used two different variable lists. Armed with that insight, you should be able to run your actual code and see what is going on.
There must be some other variable that starts with ascvd_ which you are not expecting.
To see it, suggest you add:
put (ascvd_:) (=);
Before the assignment statement.
That should show you all of the variables in the ascvd_: variable list.
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.