HI
I want to Know the position of first occurence of '~LX' or '~HL' or '~SE' whichever comes first.
I don't now why the code is not WorKing.
I will really appreciate your help.
data s1;
input string :$2000.;
Datalines;
SV1*HC+99348+LM*25+KX++++CARE*84*UN*1*12**1~DTP*472*RD8*20180720-20180720~LX*1~
SV1*HC+11721+59+~HL*1~*Q8+XX++CARE*47*UN*1*~LX*1~*12**2+3~DTP*472*RD8*20180720-20180720~REF*6R*2~
SV1*HC+11057+Q8+JX++~HL*+LX+CARE*70*UN*1*12**4+1~DTP*472*RD8*~LX*4~20180720-20180720~REF
SV1*HC+~SE+99213+LX+~SE+++CARE*150*UN*1*11**1+2~DTP*472*RD8*~LX*2~*20181004-20181004~REF*
;
data s2;
set s1;
word1= indexc(String,'~LX', '~HL','SE') ;
run;
INDEXC is used to get the position of a character in a string.
You may enter a list of characters to search for if any is found the position of first of them will be in result.
As same line may have any searched string more than once you must check each separately.
That can be done either by INDEX() or by FIND() functions.
For example:
data want;
set have;
pos1 = index(string,'~LX');
pos2 = index(string,'~HL');
pos3 = index(string,'SE');
.....
word = min(pos1-pos3);
run;
If you are looking for first '~' character you can use INDEX / INDEXC / FIND functions;
word = indexc(string,'~');
Read the manual:
Particularly:
INDEXC is used to get the position of a character in a string.
You may enter a list of characters to search for if any is found the position of first of them will be in result.
As same line may have any searched string more than once you must check each separately.
That can be done either by INDEX() or by FIND() functions.
For example:
data want;
set have;
pos1 = index(string,'~LX');
pos2 = index(string,'~HL');
pos3 = index(string,'SE');
.....
word = min(pos1-pos3);
run;
If you are looking for first '~' character you can use INDEX / INDEXC / FIND functions;
word = indexc(string,'~');
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.