```Date: Fri, 4 Aug 2006 16:38:47 -0500 Reply-To: PuddingDotManAtGmailDotCom@listserv.cc.uga.edu Sender: "SAS(r) Discussion" From: Pudding Man Subject: Re: Logic Function To Return Character Value? Comments: To: Paul Walker In-Reply-To: <200608032210.k73IwAee021883@mailgw.cc.uga.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed I dunno what you're up to here, but if you are running V9, there might be a good case to be made for the IFC function: 62 data _null_; 63 x = ranuni(0); 64 y = catx(' ', 'The lucky number is', ifc(x > 0.5, 'A', 'B', 'Implausable')); 65 put x= y=; 66 run; INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation may result. 64:3 y x=0.1786579137 y=The lucky number is B Might wanna add a LENGTH statement for Y. IFC/IFN are not known for performance but with "small data" this is likely not an issue. CATX is also V9. Slainte, Puddin' ***************************************************************** *** Puddin' Man PuddingDotMan at GmailDotCom ** *****************************************************************; On 8/3/06, Paul Walker wrote: > To return a particular numeric value when a condition is met you can use > the logic function, e.g. > > data _null_; > x = ranuni(0); > y = 'The lucky number is '||trim(left(7*(x>0.5)+12*(x<0.5)))||'.'; > put y; > run; > > Half the time this should return 7, half the time 12. > > Now, I want to do the same thing, but instead return a character. The > analogous code is: > > data _null_; > x = ranuni(0); > y = 'The lucky letter is '||trim(left('A'*(x>0.5)+'B'*(x<0.5)))||'.'; > put y; > run; > > But obviously this does not work because a character times a number in SAS > equals missing, e.g. 'A'*1=. > > So, does anyone have any trick to achive the above? I want it to be done > in one function that can be nested [as in the example] and not use if-then- > else logic over multiple lines. > ```

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