<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: extract letter form alphabet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922241#M363169</link>
    <description>Hi Patrick,&lt;BR /&gt;Thank you very much your detailed solution</description>
    <pubDate>Fri, 29 Mar 2024 07:40:09 GMT</pubDate>
    <dc:creator>pavank</dc:creator>
    <dc:date>2024-03-29T07:40:09Z</dc:date>
    <item>
      <title>extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922089#M363120</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dsn;
    length string $26; 
 string = 'abcdefghijklmnopqrstuvwxyz';
      do i = 1 to length(string);
     if i =1 then do;from_string=substr(string,i-1);end;
         from_string = cat(substr(string, 1, i-1), substr(string, i+1));
      extract_letter = substr(string, i, 1); 
      output;
    end;
    drop i;
    proc print noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;i want ouput like below i want extract each letter from string variable that letter should not be in from_string variabe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pavank_0-1711627911973.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94993i58768A30839E6969/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pavank_0-1711627911973.png" alt="pavank_0-1711627911973.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 12:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922089#M363120</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2024-03-28T12:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922103#M363126</link>
      <description>&lt;P&gt;So what is your question? What is wrong with the code you show?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 13:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922103#M363126</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-28T13:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922112#M363130</link>
      <description>&lt;P&gt;Is case of the letter to be considered? "A" is not the same as "a" for example.&lt;/P&gt;
&lt;P&gt;Is the "letter" you want to remove duplicated in your actual values? Should the process remove just one instance of the letter? All instances? Something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would probably use the COMPRESS function but that depends on the answers above. The Compress function would remove multiple instances of the letter and has options to ignore case, so "a" and "A" could both be removed.&lt;/P&gt;
&lt;PRE&gt;data dsn;
    length string $26; 
    string = 'abcdefghijklmnopqrstuvwxyz';
    length from_string $ 26;
     do i = 1 to length(string);
         extract_letter = substr(string, i, 1); 
         from_string=compress(string,extract_letter);
      output;
    end;
    drop i;
run;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2024 13:45:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922112#M363130</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-03-28T13:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922134#M363135</link>
      <description>&lt;P&gt;Does below return what you're after?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  length string from_string extract_letters $26;
  string = 'abcdefghijklmnopqrstuvwxyz';
  from_string='acdefghijklmnopqrstuvwxyz';
  extract_letters=compress(string,strip(from_string));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922134#M363135</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-28T15:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922228#M363160</link>
      <description>&lt;P&gt;I guess what you want to do is march through STRING one character at a time.&amp;nbsp; For each iteration, extract the corresponding character, and generate FROM_STRING as STRING minus that character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If each character in STRING is unique, then compress is all you need:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  string='abcdefghijklmnopqrstuvwxyz';
  do _i=1 to length(string);
    extract_letter=char(string,_i);
    from_string=compress(string,extract_letter);
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if some characters appear more than once in STRING, but you still want to remove characters only one at a time, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  string='abcdefghijklmnopqrstuvwxyz';

  do _i=1 to length(string);
    extract_letter=char(string,_i);
    substr(string,_i,1)='*';
    from_string=compress(string,'*');
    substr(string,_i,1)=extract_letter;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The latter code inserts an asterisk in the location of the extracted letter, followed by compressing out the asterisk in generating FROM_STRING.&amp;nbsp; Then the extract_letter is restored to its original position in STRING.&amp;nbsp; Of course, this assumes that an asterisk never appears in the original string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "trick" here is the use of the SUBSTR function on the left side (i.e. the result side) of the equals sign.&amp;nbsp; It's not a usage one would assume exists.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 02:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922228#M363160</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-03-29T02:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922234#M363165</link>
      <description>&lt;P&gt;Here a picklist depending on what you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dlm=' ';
  input string:$26. from_string:$26.;
  datalines;
abcdefghijklmnopqrstuvwxyz acdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz aCdefghijklmnopqrstuvwxyz
babdEfghijklmnopqrstuvwxyz cdefghijklMnopqrstuvwxyz
;


/* case insensitive processing */
%let ra=%sysfunc(rank(a));
%let rz=%sysfunc(rank(z));

data want;
  set have;
  length extract_letters extract_letters_unique $26;

  /* get all letters in string that don't exist in from_string - case insensitive */
  extract_letters=compress(string,strip(from_string),'i');

  /* only list delta delta letters once - case insensitive */
  length letter $1;
  array charlist{&amp;amp;ra:&amp;amp;rz} $1 _temporary_;
  do i=1 to length(extract_letters);
    letter=substr(extract_letters,i);
    charlist[rank(lowcase(letter))]=letter;
  end;
  extract_letters_unique=cats(of charlist[*]);
  drop letter i;
run;

proc print data=want;
run;


/* case sensitive processing */
%let ra=%sysfunc(rank(a));
%let rz=%sysfunc(rank(z));

data want2;
  set have;
  length extract_letters extract_letters_unique $26;

  /* get all letters in string that don't exist in from_string - case sensitive */
  extract_letters=compress(string,strip(from_string));

  /* only list delta delta letters once - case sensitive */
  length letter $1;
  array charlist{&amp;amp;ra:&amp;amp;rz,0:1} $1 _temporary_;
  do i=1 to length(extract_letters);
    letter=substr(extract_letters,i);
    l_num =rank(letter);
    l_case= &amp;amp;ra&amp;lt;=l_num&amp;lt;=&amp;amp;rz;
    if l_case=0 then l_num= rank(lowcase(letter));
    charlist[l_num,l_case]=letter;
  end;
  extract_letters_unique=cats(of charlist[*]);
  call missing(of charlist[*]);
  drop letter i l_num l_case;
run;

proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1711689135985.png" style="width: 525px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95027i5C94264DBA5E73E4/image-dimensions/525x214?v=v2" width="525" height="214" role="button" title="Patrick_0-1711689135985.png" alt="Patrick_0-1711689135985.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 05:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922234#M363165</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-03-29T05:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922240#M363168</link>
      <description>&lt;P&gt;Hi Mkeintz,&lt;/P&gt;
&lt;P&gt;Thank you very much for your solution&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2024 07:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922240#M363168</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2024-03-29T07:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: extract letter form alphabet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922241#M363169</link>
      <description>Hi Patrick,&lt;BR /&gt;Thank you very much your detailed solution</description>
      <pubDate>Fri, 29 Mar 2024 07:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-letter-form-alphabet/m-p/922241#M363169</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2024-03-29T07:40:09Z</dc:date>
    </item>
  </channel>
</rss>

