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;