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 (September 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 10 Sep 2009 07:19:28 -0500
Reply-To:   "Data _null_;" <iebupdte@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Data _null_;" <iebupdte@GMAIL.COM>
Subject:   Re: Table Driven Waterfall
Comments:   To: "Nallapeta1, Kiran (GE Money, consultant)" <Kiran.Nallapeta1@ge.com>
In-Reply-To:   <02A488C2B738A24DA8125FF1ABE84B14065BB5B9@ALPMLVEM17.e2k.ad.ge.com>
Content-Type:   text/plain; charset=ISO-8859-1

How about just using "data condition" and PUT to write some code that gets %INCed.

data _null_; set condition; if _n_ gt 1 then put 'Else ' @; put 'IF (' condition ') then ' result ';'; run;

You would want to write this to a file of course. I wish the OP would post a better sample of his actual data as he implies that it is more complicated.

On 9/10/09, Nallapeta1, Kiran (GE Money, consultant) <Kiran.Nallapeta1@ge.com> wrote: > Perry... I think this is what you are looking for. The below code builds > IF-ELSE statements dynamically from a table. > > ------------------ > /* Building Conditions and Results table */ > data condition; > length condition $50. result $50.; > infile cards dlm=',' missover pad; > input condition $ result $; > cards; > a < 3, z=0 > a > 3 and a lt 10, z=2 > a in (2 3 4), z=9 > a ne 0, z=1 > ; > run; > > /*Building IF-ELSE Logic/String*/ > %macro build_code; > proc sql noprint; > select condition, result > into :conds separated by "#", :res separated by "#" > from condition; > quit; > > %global fullstr; > > data condition2; > do i = 1 to &sqlobs; > cond = scan("&conds", i, "#"); > rest = scan("&res", i, "#"); > > str = "if " || cond || " then " || rest || ";"; > if i ne &sqlobs then str1 = str || " else"; > else str1 = str; > > length full_str $300.; > full_str = compbl(full_str || str1); > end; > call symput("fullstr", full_str); > run; > > /*Prints the IF-Else String to log*/ > %put &fullstr; > > /*Apply the IF-ELSE logic to below sample data*/ > data sample; > a=6; output; > a=3; output; > a=4; output; > a=50; output; > run; > data final; > set sample; > &fullstr; > run; > > %mend build_code; > > %build_code; > ------------------ > Thanks, > Kiran > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Perry > Sent: Thursday, September 03, 2009 6:05 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Table Driven Waterfall > > I'm hoping that someone out there has done something similar to what I > need as I'm really looking for assistance in figuring out an ideal > table structure for my task. > > I have one dataset of selection criteria, basically a list of many > simple logical constructs, e.g. (x le 10000) or (y not in > ('A','B','C'). I want to define another table that combines (by > reference) any number of these simple criteria into a cascading set of > if..then..else statements. > > In other words, I want to be able to create macro arrays to generate > statements like: > > if criteria1 then .... ; else > if criteria2 then .... ; else > > etc. > > However, criteria<n> can (and will) be more complex than just a single > construct in the selection criteria table. > > Hopefully, I have provided enough information to convey what I am > looking for. Eventually, I could probably come up with a workable (but > probably flawed) solution, but am hoping to tap into the vast > expertise and experience of the list to see if someone has already > implemented something similar. > > TIA > Perry >


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