Barite | Level 11

## Sum Function

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)

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Sum Function

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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
5 REPLIES 5
Rhodochrosite | Level 12

## Re: Sum Function

The variable

ascvd_score

is in your first list (of ascdv_) but not the second.

Barite | Level 11

## Re: Sum Function

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?

Super User

## Re: Sum Function

What if the variable is already in the incoming dataset?

Rhodochrosite | Level 12

## Re: Sum Function

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.

Super User

## Re: Sum Function

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.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
Discussion stats
• 5 replies
• 650 views
• 6 likes
• 4 in conversation