turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- dividing 2 sum_values

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-15-2011 12:26 PM

Is is possible to divide 2 sum_values together accurately? I am aware that the sum values will carry over, and that is why so far I am not getting the correct answer, is there another function I can use to divide 2 sum_values?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-15-2011 05:38 PM

Please be more clear. Are you in a procedure, datastep, proc report?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-15-2011 05:58 PM

Here is the code I have written, detailing where I am running into problems,

/** combine two age groups and calculate the percentage of the poverty level with the same data set**/

data pov4;

set pov;

if age = 'under12' or age = 'under18' then sum_value + fpl100;

run;

proc print data = pov4;

title '5-18fpl100test';

run;

/**this is the part that the sum is coming up incorrect**/

data pov5;

set pov4;

if age = 'under12' or age = 'under18' then sum_value + total;

run;

proc print data = pov5;

title 'sumtotalof5-18poptest';

run;

data pov6;

set pov5;

percent = sum_value + fpl100 / sum_value + total * 100;

run;

proc print data = pov6;

title 'percentage of 5-17fpl100';

run;

/** combine two age groups and calculate the percentage of the poverty level with the same data set**/

data pov4;

set pov;

if age = 'under12' or age = 'under18' then sum_value + fpl100;

run;

proc print data = pov4;

title '5-18fpl100test';

run;

/**this is the part that the sum is coming up incorrect**/

data pov5;

set pov4;

if age = 'under12' or age = 'under18' then sum_value + total;

run;

proc print data = pov5;

title 'sumtotalof5-18poptest';

run;

data pov6;

set pov5;

percent = sum_value + fpl100 / sum_value + total * 100;

run;

proc print data = pov6;

title 'percentage of 5-17fpl100';

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-15-2011 06:48 PM

CGI,

Without seeing your data, I am not sure how to answer this. Honestly, you appear to need a class on SAS basics like the data step vector. I am going to show you two ways to do this. The first is similar to what you tried, the second is closer to how I would actually do it.

I am assuming your data looks something like this. However, I am sure it is much more complicated.

data pov;

length age $ 7;

age = 'under05'; total = 100; fpl100 = 20; output;

age = 'under12'; total = 300; fpl100 = 50; output;

age = 'under18'; total = 250; fpl100 = 60; output;

age = 'under40'; total = 1000; fpl100 = 100; output;

run;

Here is how I__wouldn't do it__ because it assumes a lot, particularly that there are no values of age that will sort in between under12 and under18. I am showing it because it only uses the SAS techniques you were using.

proc sort data=pov;

by age;

run;

data pov5b(drop = fpl100 total) ;

set pov;

retain sum_fpl100 sum_total;

sum_fpl100 = sum(sum_fpl100,fpl100);

sum_total = sum(sum_total,total);

if age ne 'under12' then do;

if age = 'under18' then age = '5-17';

percent = sum_fpl100 / sum_total;

output;

sum_fpl100 = 0;

sum_total = 0;

end;

run;

This is a more robust way of doing it, but it requires that you understand SAS formats and proc summary. Note that if a format is passed a value that is it not written to handle, will return the value passed to it it. For this reason, only the affected age categories are listed.:

proc format;

value $newage

'under12' , 'under18' = '5-18pop';

run;

proc summary noprint nway data=pov;

var total fpl100;

class age;

format age $newage.;

output out = pov5 sum=;

run;

data pov6;

set pov5;

percent = fpl100 / total;

run;

Without seeing your data, I am not sure how to answer this. Honestly, you appear to need a class on SAS basics like the data step vector. I am going to show you two ways to do this. The first is similar to what you tried, the second is closer to how I would actually do it.

I am assuming your data looks something like this. However, I am sure it is much more complicated.

data pov;

length age $ 7;

age = 'under05'; total = 100; fpl100 = 20; output;

age = 'under12'; total = 300; fpl100 = 50; output;

age = 'under18'; total = 250; fpl100 = 60; output;

age = 'under40'; total = 1000; fpl100 = 100; output;

run;

Here is how I

proc sort data=pov;

by age;

run;

data pov5b(drop = fpl100 total) ;

set pov;

retain sum_fpl100 sum_total;

sum_fpl100 = sum(sum_fpl100,fpl100);

sum_total = sum(sum_total,total);

if age ne 'under12' then do;

if age = 'under18' then age = '5-17';

percent = sum_fpl100 / sum_total;

output;

sum_fpl100 = 0;

sum_total = 0;

end;

run;

This is a more robust way of doing it, but it requires that you understand SAS formats and proc summary. Note that if a format is passed a value that is it not written to handle, will return the value passed to it it. For this reason, only the affected age categories are listed.:

proc format;

value $newage

'under12' , 'under18' = '5-18pop';

run;

proc summary noprint nway data=pov;

var total fpl100;

class age;

format age $newage.;

output out = pov5 sum=;

run;

data pov6;

set pov5;

percent = fpl100 / total;

run;