LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2008, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 17 Dec 2008 14:28:25 -0800
Reply-To:     Bill McKirgan <Bill.McKirgan@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bill McKirgan <Bill.McKirgan@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: comparing score range between variables
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

On Dec 17, 3:58 pm, chang_y_ch...@HOTMAIL.COM (Chang Chung) wrote: > On Wed, 17 Dec 2008 13:19:55 -0800, Bill McKirgan <Bill.McKir...@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; > > hi, Bill, > here is one way of using abs() function. it is easy to write a simple > function (in 9.2) or a function-style macro. If you have many *many* such > pairs of vars, then you may need other solutions. hth. > cheers, > chang > > /* test data */ > data one; > input piq fsiq; > cards; > 0 0 > 1 6 > 6 3 > 1 7 > 2 . > ; > run; > > /* a simple function-style macro to calc a flag */ > %macro within5(var1, var2); > (ifn(missing(&var1) or missing(&var2) > , . %*-- missing --*; > , ifn(abs(&var1 - &var2)<=5, 1,0))) > %mend within5; > > /* make flags */ > data two; > set one; > piq5 = %within5(piq, fsiq); > run; > > /* check */ > proc print data=two noobs; > run; > /* on lst > piq fsiq piq5 > 0 0 1 > 1 6 1 > 6 3 1 > 1 7 0 > 2 . . > */- Hide quoted text - > > - Show quoted text -

Thank you Chang Chung, and Joe. Using the abs() function is what I needed to shorten this up.

Best regards, Bill


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