<?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 if condition in a data step in order to check for character strings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-condition-in-a-data-step-in-order-to-check-for-character/m-p/86551#M18525</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just started to use SAS and need some help for an urgent paper. My data set contains an alphanumeric variable where the first position is a character followed by a four digit number. I want to create a new variable which has the value one if the character plus the first three digits of the number match. F.e. the value of the variable M968 should be 1 if the observation contains "M968", so an obeservation with "M9680" would be one and "M9670" would be zero.&lt;/P&gt;&lt;P&gt;My following code only recognizes if the complete value matches:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data multimorbid;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set library.file;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M968 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if icd_hd = 'M968' then M968=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to use the where statement, because I can use the operator contains, but using the where statement creates only a subset of observations which contain the character strings, but I want that the new variable M968 is added to the complete data set multimorbid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Dennis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 23 Mar 2013 17:28:39 GMT</pubDate>
    <dc:creator>dennisl</dc:creator>
    <dc:date>2013-03-23T17:28:39Z</dc:date>
    <item>
      <title>if condition in a data step in order to check for character strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-condition-in-a-data-step-in-order-to-check-for-character/m-p/86551#M18525</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just started to use SAS and need some help for an urgent paper. My data set contains an alphanumeric variable where the first position is a character followed by a four digit number. I want to create a new variable which has the value one if the character plus the first three digits of the number match. F.e. the value of the variable M968 should be 1 if the observation contains "M968", so an obeservation with "M9680" would be one and "M9670" would be zero.&lt;/P&gt;&lt;P&gt;My following code only recognizes if the complete value matches:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data multimorbid;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set library.file;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M968 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if icd_hd = 'M968' then M968=1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to use the where statement, because I can use the operator contains, but using the where statement creates only a subset of observations which contain the character strings, but I want that the new variable M968 is added to the complete data set multimorbid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Dennis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 17:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-condition-in-a-data-step-in-order-to-check-for-character/m-p/86551#M18525</guid>
      <dc:creator>dennisl</dc:creator>
      <dc:date>2013-03-23T17:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: if condition in a data step in order to check for character strings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-condition-in-a-data-step-in-order-to-check-for-character/m-p/86552#M18526</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Try using the operator =: which checks if the variable starts with M968&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Or&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;You can use the substring function:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if substr(icd_hd, 1, 4)="M968" then M968=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data multimorbid;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set library.file;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M968 = 0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if icd_hd =: 'M968' then M968=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 23 Mar 2013 17:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-condition-in-a-data-step-in-order-to-check-for-character/m-p/86552#M18526</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-03-23T17:55:27Z</dc:date>
    </item>
  </channel>
</rss>

