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 (August 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 4 Aug 2006 16:38:47 -0500
Reply-To:     PuddingDotManAtGmailDotCom@listserv.cc.uga.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Pudding Man <pudding.man@GMAIL.COM>
Subject:      Re: Logic Function To Return Character Value?
Comments: To: Paul Walker <walker.627@osu.edu>
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 <walker.627@osu.edu> 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