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 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 18 Sep 2009 15:19:10 -0400
Reply-To:     Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject:      Re: Using PUT() and CONTAINS in a Conditional Statement XXX
Comments: To: Dan Abner <dan.abner99@GMAIL.COM>
In-Reply-To:  <d18436ce0909180723m5a16b4dm171d253d96d2543a@mail.gmail.com>
Content-Type: text/plain; charset="us-ascii"

Dan: The SAS INDEX() function/operator returns a Boolean value of TRUE (NOT zero) if a string contains another string:

data test; input PNUM PRES; cards; 111 123 222222 456 399933 . 99999999 789 33339999 . 98989898 . ; run; data contains; set test; /* IF PUT(PNUM,*6.*) CONTAINS '9999' THEN CALL MISSING(PRES); */ if index(put(PNUM,16.),'9999') then CALL MISSING(PRES); put PRES; run;

The CONTAINS operator works equivalently in a CASE WHEN THEN END clause in SAS SQL:

proc sql; select *,case when PUT(PNUM,16.) CONTAINS '9999' then . else PRES end as PRES from test ; quit;

S

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Dan Abner Sent: Friday, September 18, 2009 10:24 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Using PUT() and CONTAINS in a Conditional Statement XXX

Hello,

I am trying to execute a conditional statement based on whether or not an identifier variable (numeric var type) contains the numbers 9999 using the CONTAINS operator. I intended to convert the num var PNUM to a char var for purposes of using the CONTAINS operator. Any ideas why this does not work? Can anyone suggest a solution?

IF PUT(PNUM,*6.*) CONTAINS '9999' THEN CALL MISSING(PRES);

Thanks,

Daniel


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