|
Thanks Dan & Toby!! I just learned a new function "scan" :-)
K.
On Tue, 23 May 2006 17:58:51 -0700, Nordlund, Dan (DSHS)
<NordlDJ@DSHS.WA.GOV> wrote:
>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Kitty
>> Lee
>> Sent: Tuesday, May 23, 2006 5:50 PM
>> To: SAS-L@LISTSERV.UGA.EDU
>> Subject: extract a string separated by '-'
>>
>> 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.
>
>Kitty,
>
>You can use the SCAN function. Try something like the following:
>
>data test;
> input CaseID $1-25;
>cards;
> 100101 - 100203
> 100101 - 1002834
> 10020 - 100390
> 1003044 - 10023045
>;
>run;
>data test2;
> length CaseID_1 CaseID_2 $15;
> set test;
> CaseID_1=compress(scan(CaseID,1,'-'));
> CaseID_2=compress(scan(CaseID,2,'-'));
>run;
>proc print;
>run;
>
>Hope this is helpful,
>
>Dan
>
>Daniel J. Nordlund
>Research and Data Analysis
>Washington State Department of Social and Health Services
>Olympia, WA 98504-5204
|