Hi,
I am trying to understand FindC function with the help of the below example
data test;
input MEDICARE_ID $ 1-64;
datalines;
_2E8a
X3628970
A2
_N_
_______
315
_ab12A:5
_error_
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabc
;
run;
data test1;
set test;
whereisit=findc(trim(upcase(MEDICARE_ID)), '2');
run;
If you run the above code, i am getting the below output
I am fine with all the output except the 3rd one where i was expecting "2" , because 2 is at 2nd location.
So, i would like to know what is wrong in my understanding.
Thanks.
That value must have some invisible characters.
Put the value using $HEX format to see what they are.
@Tom:
It could hardly be explained by the presence of invisible characters, either: The string is searched left-to-right and begins with "A2", all of whose characters are printable. Most likely, the real data are different from the sample presented in the original post.
Paul D.
It can be explained only if you run your test test against data different from the sample data you've presented here. When I run it against your data verbatim, I get the output just as expected - and as should be expected. The FINDC function, the way you call it, finds the leftmost occurrence of "2" in each string where "2" is present. For "A2", it returns 2. No one can help you with a problem if it cannot be replicated.
Paul D.
Hi @shahsn11,
When I run your program and print dataset TEST1, two previously invisible characters appear in the output window. Both are displayed as question marks.
Partial output:
Obs MEDICARE_ID whereisit 1 _2E8?a 2 2 X3628970 4 3 A?2 3
Obviously, the second occurrence has an impact on the result.
However, when I copy your program into a Notepad (notepad.exe) window, save the file using UTF-8 coding and then open it in a hex editor, the above two "question marks" turn out to be three characters each: The sequence of hex codes is E2 81 AA in both cases. This would explain exactly the result whereisit=5 for the third observation.
Note that if you data is not using a single byte character set then you need to use KINDEXC() function.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.