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 (May 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, 23 May 2006 20:01:19 -0500
Reply-To:     Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject:      Re: extract a string separated by '-'
Comments: To: Kitty Lee <lee.kitty@YAHOO.COM>
Content-Type: text/plain; charset=US-ASCII

Kitty:

Here is an implementation and its output.

data temp; length CaseID_1 CaseID_2 $ 15; input CaseID $ 1-30; CaseID_1=compress(scan(CaseID,1,'-')),best.)); CaseID_2=compress(scan(CaseID,2,'-')); datalines; 100101 - 100203 100101 - 1002834 10020 - 100390 1003044 - 10023045 ; run;

proc print; run;

***** OUTPUT ***** The SAS System 08:37 Tuesday, May 23, 2006 19

Case Obs CaseID ID_1 CaseID_2

1 100101 - 100203 100101 100203 2 100101 - 1002834 100101 1002834 3 10020 - 100390 10020 100390 4 1003044 - 10023045 1003044 10023045

J S Huang 1-515-557-3987 fax 1-515-557-2422

>>> Kitty Lee <lee.kitty@YAHOO.COM> 05/23/06 7:50 PM >>> Hi. I have a question about extracting caseid

My current variable, CASEID has two components separated by '-'. It looks like this:

CaseID 100101 - 100203 100101 - 1002834 10020 - 100390 1003044 - 10023045

I wonder how can I separate out the two columns to become something like:

CaseID_1 CaseID_2

100101 100203 100101 1002834 10020 100390 1003044 10023045

I can't use simple substr(string, start, length) because the length of the CaseIDs varies. The only clear separator is '-'.

Thanks. :-)

K.


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