Desktop productivity for business analysts and programmers

How To find string in one field with 2 delimiter

Reply
Occasional Contributor
Posts: 8

How To find string in one field with 2 delimiter

Need help!!

I have data field look like this :

78687hkjkjh43@hsak-786778@hhjjjh762lkjklll

I want to get data beetween delimiter @.....@ I want get value hsak-786778
Thx for your help....

data getstr1(keep=memo test);
set Sastbl.sas;
test=input(delimiter="@" and "@",$10.);
run;

this can't solve my problem, any other solution please advice.thx....
SAS Employee
Posts: 6

Re: How To find string in one field with 2 delimiter

Does not look nice, but formula should be
(SUBSTR(t1.A, Find(t1.a,'@')+1,Find(t1.a,'@',Find(t1.a,'@')+1)-Find(t1.a,'@')-1))

if You string contains in variable t1.A (I used EG for testing)
Hopefully You have not need to convert in this way million of rows.

P.S. I would add befoire this statement checks, that string really contains two pieces of @ sign.

/oleg
Super Contributor
Super Contributor
Posts: 365

Re: How To find string in one field with 2 delimiter

Hello YadiAcho,

This is another solution:
[pre]
data a;
i="78687hkjkjh43@hsak-786778@hhjjjh762lkjklll";
r=SCAN(i,2,'@');
run;
[/pre]
Sincerely,
SPR
Occasional Contributor
Posts: 8

Re: How To find string in one field with 2 delimiter

thx...

it works...
Community Manager
Posts: 2,888

Re: How To find string in one field with 2 delimiter

And as a general-purpose pattern-matching approach, regular expressions work great. Check out the PRXMATCH function.

http://www2.sas.com/proceedings/sugi29/129-29.pdf

Chris
Ask a Question
Discussion stats
  • 4 replies
  • 134 views
  • 0 likes
  • 4 in conversation