```Date: Thu, 18 Dec 2008 10:50:12 -0500 Reply-To: "Howard Schreier " Sender: "SAS(r) Discussion" From: "Howard Schreier " Subject: Re: comparing score range between variables On Thu, 18 Dec 2008 07:29:39 -0800, Bill McKirgan wrote: >On Dec 17, 9:34 pm, hs AT dc-sug DOT org ("Howard Schreier)" wrote: >> On Wed, 17 Dec 2008 13:19:55 -0800, Bill McKirgan >> 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);- Hide quoted text - >> >> - Show quoted text - > >Howard, > >I can see this works, but I must confess, I don't understand how 'in >(-5 : 5)' works as it does. > >Can you explain it a bit for me? > >Many thanks, >Bill See the documentation for the IN operator: http://tinyurl.com/4w5hen or http://support.sas.com/documentation/cdl/en/lrcon/59522/HTML/default/a000780367.htm ```

Back to: Top of message | Previous page | Main SAS-L page