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 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 22 Aug 2006 17:47:11 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: Look up in data step
Comments: To: clinton.rickards@GE.COM
In-Reply-To:  <533D18F7F697A04DAA0BDB196E0871C1021D19C2@ALPMLVEM05.e2k.ad.ge.com>
Content-Type: text/plain; format=flowed

Geez this seems like an infinitly more stable approach:

Data Sample ; id = '12345V' ; output ; id = '12345X ' ; output ; id = '12345W' ; output ; id = '12345A ' ; output ; id = '12345D' ; output ; id = '123456' ; output ; Run ;

Data Need ; Length Flag1 $ 1 ; Set Sample ; Flag1 = IFC( AnyAlpha( Substr( Id , Length( Id ) ) ) > 0 , Substr( Id , Length( Id ) ) , ' ' ) ; Put ID= FLAG1= ; Run;

Toby Dunn

When everything is coming at you all at once, your in the wrong lane.

A truly happy person is someone who can smile and enjoy the scenery on a detour.

From: "Rickards, Clinton (GE Money)" <clinton.rickards@GE.COM> Reply-To: "Rickards, Clinton (GE Money)" <clinton.rickards@GE.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Look up in data step Date: Tue, 22 Aug 2006 13:31:21 -0400

All,

Be careful when using the reverse function. If the value of ID has trailing blanks then you will get a blank as the first character of the reversed value. Use a nested LEFT function as well:

data sample; length id $8; id = '12345V'; output; id = '12345X'; output; id = '12345W'; output; id = '12345A'; output; id = '12345D'; output; run;

* Method 2 of checking last character ; data result; set sample; select (substr(LEFT(reverse(id)),1,1)); when ('A') flag = 'was A '; when ('D') flag = 'was D '; when ('W') flag = 'was W '; otherwise flag = 'unknown'; end; put _all_; run;

Clint

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Terjeson, Mark (IM&R) Sent: Tuesday, August 22, 2006 12:08 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Look up in data step

Hi,

Shown are two methods of checking the last character. The SELECT/WHEN is an alternative to multiple IF/THEN statements.

data sample; id = '12345V'; output; id = '12345X'; output; id = '12345W'; output; id = '12345A'; output; id = '12345D'; output; run;

* Method 1 of checking last character ; data result; set sample; select (substr(id,length(id),1)); when ('A') flag = 'was A '; when ('D') flag = 'was D '; when ('W') flag = 'was W '; otherwise flag = 'unknown'; end; put _all_; run;

* Method 2 of checking last character ; data result; set sample; select (substr(reverse(id),1,1)); when ('A') flag = 'was A '; when ('D') flag = 'was D '; when ('W') flag = 'was W '; otherwise flag = 'unknown'; end; put _all_; run;

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Ran S Sent: Tuesday, August 22, 2006 8:51 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Look up in data step

Hi,

I have ID that ends with different alphabets A,D,l,K. How can I look for these IDs in Data step and separate them out? Do we have 'like' operator that we can use in Data step?

Thanks in advance!


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