- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello team,
I have a string as this: 1234568F888.
I need to find the position of the character in this string.
Any help is greatly appreciated.
Blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
hi @GN0001
I'd use prxmatch to get the index.
example below
data _null_;
have = "1234568F888";
want = prxmatch('([A-Za-z])',have);
put want;
run;
thanks
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Harry,
This didn't work. it gave me 17.
Thanks for your input anyway.
Respectfully,
Blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Blue
That's odd it gave you 17. I've just re-ran it in my environment, it gives me the correct position at 8.
Is it giving you 17 when you apply it to your real dataset?
Thanks
Harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I used it in in substr,
Thanks for it,
Respectfully,
Blue blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The ANYALPHA function would also work here
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I tried to use anyalpha, but I couldn't.
Can you please kindly guide me?
Regards,
blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@GN0001 wrote:
Hello,
I tried to use anyalpha, but I couldn't.
Can you please kindly guide me?
Regards,
blue
We have talked about this. Do not say it doesn't work without giving more information — specifically we need you to provide the code you tried, the input data (if it is not in the code itself) and the output. And we shouldn't have to ask for this in every thread.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I always Google before posting my question to this forum if I can’t find the answer, or if I find the answer, again I want to make sure that what I am trying to do is 100 percent correct.
Please kindly bear with me.
Regards
Blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For the data you presented, the suggested methods work, period.
Applying those methods to your real data is now your task. Different data, different results.
If you need further help, supply usable example data (DATA step with DATALINES) where you make up fake data which resembles the original data structure, and show the expected result from this fake data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I need to use this in a substr function, to get all the string till 17 or till whatever number Anyalpha gives.
Regards,
blue
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi @GN0001 ,
if you're getting 17 with both PRXPARSE and ANYALPHA then it sounds like you just need to do the substring from this?
You can feed the output of either approach into the SUBSTR function.
data _null_;
have = "1234568F888";
want = prxmatch('([A-Za-z])',have);
put "character at: " want;
/* substring until char */
want2 = substr(have,1,want-1); *everything until F;
want3 = substr(have,want+1); *everything after F;
put want2;
put want3;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
So are you using a double byte character set? That might return 17 instead of 9 since each character would take 2 bytes in the string the 9 character would start in the 17th byte.
Or perhaps your string has leading spaces that you are not seeing either because you use PUT with the $ format instead of the $CHAR or $QUOTE format. Or you looked that the ODS output instead of the LISTING (PRINT) output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you're really dealing with a multibyte character set then you need to tell us clearly. For a multibyte character set one can only use string functions on I18N Level 2.
Which functions are suitable is fully documented here.
From what you write I believe you want the substring of digits up-to the first character in the string. If so then why not use the scan() function ...or kscanx() for multibyte.
data test;
infile datalines truncover;
input str $20.;
first_char_pos=kfindc(str,,'kd');
digits_until_first_char=kscanx(str,1,'','kd');
datalines;
1234568F888
;
proc print data=test;
run;