|
On Wed, 17 Dec 2008 13:19:55 -0800, Bill McKirgan <Bill.McKirgan@GMAIL.COM>
wrote:
>Hi SASers,
>
>I'm trying to think of a more elegant (read shorter) way of coding the
>example I provide below. In the example I am comparing a variable
>called FSIQ with another variable PIQ to see if PIQ is within plus/
>minus 5 points of FSIQ. This works, but I need to apply it to a bunch
>of other variables, and would like to avoid a large copy/paste/modify
>job that may cause me to introduce errors.
>
>Can anyone suggest one or more shorter ways of doing this? Perhaps an
>array? Any help would be greatly appreciated. I'm stumped. Many
>thanks in advance.
>
>-- Bill
>
>
>data testing; set itbs.iq_data_final;
>
>piq_within_5pts = 0;
>
>if fsiq = piq then piq_within_5pts = 1; else
>
>if fsiq = piq + 1 then piq_within_5pts = 1; else
>if fsiq = piq + 2 then piq_within_5pts = 1; else
>if fsiq = piq + 3 then piq_within_5pts = 1; else
>if fsiq = piq + 4 then piq_within_5pts = 1; else
>if fsiq = piq + 5 then piq_within_5pts = 1; else
>
>if fsiq = piq - 1 then piq_within_5pts = 1; else
>if fsiq = piq - 2 then piq_within_5pts = 1; else
>if fsiq = piq - 3 then piq_within_5pts = 1; else
>if fsiq = piq - 4 then piq_within_5pts = 1; else
>if fsiq = piq - 5 then piq_within_5pts = 1;
>
>put fsiq piq @20 piq_within_5pts ;
>
>run;
I trust that there are no missing values. Bill's code actually returns a 1
(true) result if both variables are missing; probably not wanted.
Here is a technique which is almost exactly equivalent, but is much shorter
and generates a 0 (false) given two missing values:
piq_within_5pts = (piq - fsiq) in (-5 : 5);
|