<?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 Using an IF ELSE statement to add a hyphen when a character is missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696073#M212526</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello SAS Communities,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am looking to change an Initials variable into the form of FML and if there is no middle initial F-L.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The current initials variable is in the form F.M.L and when there is no middle initial it looks like this F. L.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is&lt;/P&gt;&lt;P&gt;Inits&lt;/P&gt;&lt;P&gt;RWP&lt;/P&gt;&lt;P&gt;NAE&lt;/P&gt;&lt;P&gt;TCJ&lt;/P&gt;&lt;P&gt;FLY&lt;/P&gt;&lt;P&gt;GSC&lt;/P&gt;&lt;P&gt;S-R&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have so far&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WORK.data ;&lt;BR /&gt;SET import.records (RENAME=(Inits = initials ID=social ZipCode=ZipCd));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Inits&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;inits2 = COMPRESS(initials, '.');&lt;BR /&gt;IF length(inits2) = 2 THEN Inits = CATX('-', CHAR(inits2, 1), CHAR(inits2, 2));&lt;BR /&gt;ELSE Inits= inits2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does not work because those with missing middle initials get outputted as just their first initial, ie S. R. is just S.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Dec 2020 19:48:33 GMT</pubDate>
    <dc:creator>hspears</dc:creator>
    <dc:date>2020-12-15T19:48:33Z</dc:date>
    <item>
      <title>Using an IF ELSE statement to add a hyphen when a character is missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696073#M212526</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello SAS Communities,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am looking to change an Initials variable into the form of FML and if there is no middle initial F-L.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The current initials variable is in the form F.M.L and when there is no middle initial it looks like this F. L.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is&lt;/P&gt;&lt;P&gt;Inits&lt;/P&gt;&lt;P&gt;RWP&lt;/P&gt;&lt;P&gt;NAE&lt;/P&gt;&lt;P&gt;TCJ&lt;/P&gt;&lt;P&gt;FLY&lt;/P&gt;&lt;P&gt;GSC&lt;/P&gt;&lt;P&gt;S-R&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I have so far&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA WORK.data ;&lt;BR /&gt;SET import.records (RENAME=(Inits = initials ID=social ZipCode=ZipCd));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Inits&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;inits2 = COMPRESS(initials, '.');&lt;BR /&gt;IF length(inits2) = 2 THEN Inits = CATX('-', CHAR(inits2, 1), CHAR(inits2, 2));&lt;BR /&gt;ELSE Inits= inits2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does not work because those with missing middle initials get outputted as just their first initial, ie S. R. is just S.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 19:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696073#M212526</guid>
      <dc:creator>hspears</dc:creator>
      <dc:date>2020-12-15T19:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using an IF ELSE statement to add a hyphen when a character is missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696089#M212537</link>
      <description>&lt;P&gt;Your test looks good. What do you dislike?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2020 05:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696089#M212537</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-03T05:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using an IF ELSE statement to add a hyphen when a character is missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696115#M212559</link>
      <description>&lt;P&gt;When you apply the COMPRESS function you remove the dots only. You need to remove blanks as well in order to get a length of 2. So the second parameter to COMPRESS should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;inits2 = COMPRESS(initials, ' .');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That will get S. R. to come out as SR.&amp;nbsp; WIthout that change, you are getting S R.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2020 10:34:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-IF-ELSE-statement-to-add-a-hyphen-when-a-character-is/m-p/696115#M212559</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-11-03T10:34:26Z</dc:date>
    </item>
  </channel>
</rss>

