BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8
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
2 REPLIES 2
PaigeMiller
Diamond | Level 26
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. 

--
Paige Miller
ballardw
Super User

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?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1146 views
  • 0 likes
  • 3 in conversation