BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

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
Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.

View solution in original post

5 REPLIES 5
WarrenKuhfeld
Ammonite | Level 13

The variable 

ascvd_score

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

_maldini_
Barite | Level 11

@WarrenKuhfeld 

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?

WarrenKuhfeld
Ammonite | Level 13

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.

Quentin
Super User

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 Boston Area SAS Users Group is hosting free webinars!
Next up: SAS Trivia Quiz hosted by SAS on Wednesday May 21.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1287 views
  • 6 likes
  • 4 in conversation