While I don't know how to do what you ask in one statement (whatever that means), you can simplify your typing as follows:
IF SUBSTR(cause,1,1)="C" THEN overall_cancer_deaths=1;
ELSE IF SUBSTR(cause,1,1) ne "C" THEN overall_cancer_deaths=0;
can be replaced with
c_deaths=(cause=:'C');
which will give you a one or zero depending on the value of variable named cause. Please note the colon after the cause= .
From there you could create a macro to compute this 0 or 1 and sum it, so you could write
%macro death(string);
sum_&string + (cause=:"&string");
%mend;
and then list all the codes like this:
data want;
set have end=eof;
array sums sum_:;
%death(C)
%death(C16)
...
if eof then do;
do i=1 to dim(sums);
sums(i)=sums(i)/(12000000*100000);
end;
output;
end;
run;
This could even be simplified further if you have all of the possible codes to be used in a SAS data set, then you can replace the typing of all %death statements with a macro loop that calls %death for each possible cause, so you don't have to type them all in. Or similar with CALL EXECUTE. I realize this isn't anywhere close to the (probably impossible) request to do it in one statement, but it seems to me it would be one of the fastest ways to code this.
Which brings us to a question I have for you. What is your real goal? To find the fastest way to program this? Or are you looking for something else? Too often, people decide upon a solution first — write it in one line — and this doesn't express their real goal here, and gives little guidance as the apparent goal of writing it in one line seems impossible.
... View more