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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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