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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info 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 (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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