<?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: Character Search and Select in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270758#M310645</link>
    <description>&lt;P&gt;The functions you are looking for could include INDEX, INDEXW, FIND, FINDW ... it all depends on what you mean when you say that REFNO "includes HLC".&amp;nbsp; Would any of these be a match:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1234HLC81A&lt;/P&gt;
&lt;P&gt;HLC25&lt;/P&gt;
&lt;P&gt;GHLC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, you would need to use INDEX or FIND.&amp;nbsp; If not, you would need to use INDEXW or FINDW.&amp;nbsp; Basically, the "W" means look for words, rather than a series of characters.&amp;nbsp; So you might use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = findw(refno, 'HLC', , 'i');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "i" at the end indicates that case should be ignored, so the function can find HLC, Hlc, hlc, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The new variable may be sufficient.&amp;nbsp; It will contain 0 if the string is not found, or an integer greater than zero when the string is found.&amp;nbsp; You can always convert the values greater than zero to 1 using IF/THEN statements.&amp;nbsp; But you likely don't have to.&amp;nbsp; For example, this statement treats "0" as false, and all other nonmissing values as true:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if newvar then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From that point, I think you just need to code a few IF/THEn statements.&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2016 19:07:38 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-05-16T19:07:38Z</dc:date>
    <item>
      <title>Character Search and Select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270742#M310644</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to perform the following action to a dataset, where variable names are in paratheses:&lt;/P&gt;&lt;P&gt;-&amp;nbsp;for ID number (ID) "2222", "2323" and "2425", &amp;nbsp;if reference number (REFNO) &amp;nbsp;includes "HLC", then the code variable (CODE) is set to "13"&lt;/P&gt;&lt;P&gt;-&amp;nbsp;for ID number (ID) is equal to "2222" and where reference number doesn't include&amp;nbsp;"HLC", the CODE is set to "99"&lt;/P&gt;&lt;P&gt;- for ID number (ID)&amp;nbsp;"2323" and "2425", and where reference number doesn't include "HLC", then the code variable (CODE) is set to "98"&lt;/P&gt;&lt;P&gt;Although, REFNO isn't of equal lenght and HLC isn't necessarily always in the same "spot".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I came across the subtring, prx, scan functions but I'm not certain they would work or if there's an easier way to go about with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First question - is there a way to scan a string/character variable for a set of characters when the set of characters (HLC) doesn't isn't necessarily always at the same spot?&lt;/P&gt;&lt;P&gt;Second - I would essentially like to create a new binary variable where if the characters "HLC" are present, then binary variable = 1&amp;nbsp;and if HLC not present within&amp;nbsp;REFNO, then binary variable =&amp;nbsp;0 and essentially use that binary variable when using the "IF, THEN, ELSE" statement. Any particular suggestions for other alternative ways to reach the same end result?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CF&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 18:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270742#M310644</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2016-05-16T18:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Character Search and Select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270758#M310645</link>
      <description>&lt;P&gt;The functions you are looking for could include INDEX, INDEXW, FIND, FINDW ... it all depends on what you mean when you say that REFNO "includes HLC".&amp;nbsp; Would any of these be a match:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1234HLC81A&lt;/P&gt;
&lt;P&gt;HLC25&lt;/P&gt;
&lt;P&gt;GHLC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, you would need to use INDEX or FIND.&amp;nbsp; If not, you would need to use INDEXW or FINDW.&amp;nbsp; Basically, the "W" means look for words, rather than a series of characters.&amp;nbsp; So you might use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = findw(refno, 'HLC', , 'i');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "i" at the end indicates that case should be ignored, so the function can find HLC, Hlc, hlc, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The new variable may be sufficient.&amp;nbsp; It will contain 0 if the string is not found, or an integer greater than zero when the string is found.&amp;nbsp; You can always convert the values greater than zero to 1 using IF/THEN statements.&amp;nbsp; But you likely don't have to.&amp;nbsp; For example, this statement treats "0" as false, and all other nonmissing values as true:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if newvar then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From that point, I think you just need to code a few IF/THEn statements.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 19:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270758#M310645</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-16T19:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Character Search and Select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270763#M310646</link>
      <description>&lt;P&gt;Thank you Astounding!&lt;/P&gt;&lt;P&gt;I tried out&amp;nbsp;your technique and it seems to work perfectly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did also use the following code below but I think that only assigns REFNO2=1 if the REFNO starts with HLC? (most of the reference number in my data sets do start with HLC but I would rather not take a chance and risk missing observations where the reference number contains 'HLC' but doesn't necessarily start with "HLC".&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; out.step05;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; out.step0;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; REFNO=:&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'HLC'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; REFNO2 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;ELSE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; REFNO2 = &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Thank you! &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;CF &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 19:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270763#M310646</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2016-05-16T19:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Character Search and Select</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270769#M310647</link>
      <description>&lt;P&gt;Yes, you're correct about the results from =:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many people think of =: as meaning "begins with".&amp;nbsp; Technically, it's something very similar.&amp;nbsp; It means that for comparison purposes, use the length of whichever string is shorter.&amp;nbsp; So these two comparisons would return identical results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if refno =: 'HLC' then refno2=1;&lt;/P&gt;
&lt;P&gt;if 'HLC' =: refno then refno2=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now it makes no sense to say "If 'HLC' begins with the value of REFNO ..."&amp;nbsp; But that's not exactly what =: means.&amp;nbsp; It really means that for purposes of making the comparison, shorten the longer string down to the length of the shorter string.&amp;nbsp; Finally, note that the colon can be used with other comparison operators, not just an equal sign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if 'A' &amp;lt;: lastname &amp;lt;: 'G';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would get you all LASTNAME values that begin with "B" through "F".&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 19:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-Search-and-Select/m-p/270769#M310647</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-16T19:43:46Z</dc:date>
    </item>
  </channel>
</rss>

