data _null_;
string = 'antioxidant';
length unique $200 position_list $200;
do i = 1 to length(string);
letter = substr(string, i, 1);
count = countc(string, letter);
if count = 1 then do;
unique = cats(unique, letter);
position_list = cats(position_list, i);
end;
end;
put unique;
put position_list;
run;
I want output position of non repeated letters like below
| Non-Repeated_Letters | O | X | D |
| antioxidant | 5 | 6 | 8 |
data nonduplicates;
string='Arnold Ziffel';
length thischar $ 1;
do pos=1 to length(string);
thischar=substr(string,pos,1);
count=countc(string,thischar);
if count=1 then output;
end;
keep pos thischar;
run;
This code treats capital C as a different letter than lower case c. Your problem description was silent about this issue.
A quick comment about the thinking involved with
position_list = cats(position_list, i);
Let's examine a hypothetical resulting position_list value of 12345.... (dots are other digits not germane at this point).
How do you tell position 1 for the first unique letter and 23 for the second from a position of 12 for the first and 34 for the second?
If I were contemplating creating such as list I would place a delimiter using the CATX function for example.
position_list = catx(',',position_list, i);
Then we would see 1,23,45... or 12,34,5... and the ambiguity goes away.
Any rules about characters other than letters?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.