<?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 colon to find all numeric values beginning with a specified number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353665#M82565</link>
    <description>&lt;P&gt;I'm using SAS 9.4.&amp;nbsp; I'm trying to collapse approximately 1000 codes into 77 groups.&amp;nbsp; In the syntax below, codes such as 170, 171, 172, etc from the UB_92_REV_CD_GP_1 variable should all go in the "170 TEST" group of the variable REV_CHAR_GP_1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UB_92_REV_CD_GP_1 variable is 4-digit numeric, while REV_CHAR_GP_1 is a character variable with a length of 65.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried several variations (one at a time, not all at once), but I can't get it to recode any value starting with 17 into the group "170 TEST".&amp;nbsp; I can only get it to work if I specify each value within the 170 range.&amp;nbsp; Isn't the colon supposed to find any value beginning with the specified number?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*THESE VARIATIONS WORK ONLY FOR 170, NOT 171, 172, ETC*/
IF UB_92_REV_CD_GP_1 in:("017","170") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 =:"170" THEN REV_CHAR_GP_1 = "170 TEST";


/*THESE VARIATIONS DO NOT WORK*/
IF UB_92_REV_CD_GP_1 in:("017","17") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:("17","017") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:('017','17') THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:(017,17) THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 =:"17" THEN REV_CHAR_GP_1 = "170 TEST";&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2017 12:43:26 GMT</pubDate>
    <dc:creator>Wolverine</dc:creator>
    <dc:date>2017-04-26T12:43:26Z</dc:date>
    <item>
      <title>Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353665#M82565</link>
      <description>&lt;P&gt;I'm using SAS 9.4.&amp;nbsp; I'm trying to collapse approximately 1000 codes into 77 groups.&amp;nbsp; In the syntax below, codes such as 170, 171, 172, etc from the UB_92_REV_CD_GP_1 variable should all go in the "170 TEST" group of the variable REV_CHAR_GP_1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UB_92_REV_CD_GP_1 variable is 4-digit numeric, while REV_CHAR_GP_1 is a character variable with a length of 65.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tried several variations (one at a time, not all at once), but I can't get it to recode any value starting with 17 into the group "170 TEST".&amp;nbsp; I can only get it to work if I specify each value within the 170 range.&amp;nbsp; Isn't the colon supposed to find any value beginning with the specified number?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*THESE VARIATIONS WORK ONLY FOR 170, NOT 171, 172, ETC*/
IF UB_92_REV_CD_GP_1 in:("017","170") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 =:"170" THEN REV_CHAR_GP_1 = "170 TEST";


/*THESE VARIATIONS DO NOT WORK*/
IF UB_92_REV_CD_GP_1 in:("017","17") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:("17","017") THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:('017','17') THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 in:(017,17) THEN REV_CHAR_GP_1 = "170 TEST";
IF UB_92_REV_CD_GP_1 =:"17" THEN REV_CHAR_GP_1 = "170 TEST";&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 12:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353665#M82565</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2017-04-26T12:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353670#M82566</link>
      <description>&lt;P&gt;Its always a good idea to post test data in the form of a datastep and what you want the output to look like. &amp;nbsp;There is likely a far better method.&lt;/P&gt;
&lt;P&gt;As to your question:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; UB_92_REV_CD_GP_1 &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;:&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"017"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"170"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;THEN&lt;/SPAN&gt; REV_CHAR_GP_1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"170 TEST"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;None of the text 171, 172 etc. start with either 017 or 170, hence why it does not work. &amp;nbsp;017171 does start with 017 and 170171 starts with 170.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you may be better of doing is taking the number part out of the string and using that, something like (and this is where test data/output comes in handy as just guessing):&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if input(scan(your_data,1," "),best.) between 170 and 179 then group="Group 170";
run;&lt;/PRE&gt;
&lt;P&gt;Using the right datatype will make your problem much simpler.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 12:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353670#M82566</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T12:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353671#M82567</link>
      <description>&lt;P&gt;What do you mean by "do not work"? What happens? Error in SASLOG, or wrong result? Show us the error in the SASLOG or explain to us the wrong result and show us (examples of)&amp;nbsp;the incoming data and the wrong result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 12:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353671#M82567</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-26T12:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353675#M82570</link>
      <description>&lt;P&gt;Of all those that you have listed here, the first two in the "do not work" section actually work.&amp;nbsp; The only exception might be if your variable could begin with a leading blank.&amp;nbsp; You might have to add to the list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; UB_92_REV_CD_GP_1 &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;:&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"17"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"017", " 17"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;THEN&lt;/SPAN&gt; REV_CHAR_GP_1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"170 TEST"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="arial,helvetica,sans-serif"&gt;&lt;SPAN class="token punctuation"&gt;If that doesn't work (and it appears from&amp;nbsp; your note that it doesn't), take a look at the data.&amp;nbsp; Take a subset of the observations (from those that you think should be selected), and try something along these lines:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;data _null_;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;set subset_with_17;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;testvar = '*' || UB_92_REV_CD_GP_1 || '*';&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;put testvar testvar $hex20.;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="courier new,courier"&gt;&lt;SPAN class="token punctuation"&gt;run;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000" face="arial,helvetica,sans-serif"&gt;&lt;SPAN class="token punctuation"&gt;Let's find out what is really in there.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353675#M82570</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-04-26T13:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353678#M82571</link>
      <description>&lt;P&gt;As I said, I tried several variations.&amp;nbsp; I understand why&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF UB_92_REV_CD_GP_1 in:("017","170") THEN REV_CHAR_GP_1 = "170 TEST";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;doesn't work, but why doesn't&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF UB_92_REV_CD_GP_1 in:("017","17") THEN REV_CHAR_GP_1 = "170 TEST";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;work?&amp;nbsp; Values such as 170, 171, 172, etc all start with 17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By "doesn't work", I mean that when I run frequencies on REV_CHAR_GP_1, the group 170 TEST does not appear in the output, even though I know that UB_92_REV_CD_GP_1 contains values such as 170, 171, 172, etc.&amp;nbsp; There are no errors or warnings in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF UB_92_REV_CD_GP_1 in:("17","017", " 17") THEN REV_CHAR_GP_1 = "170 TEST";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does not work either.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353678#M82571</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2017-04-26T13:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353680#M82572</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Post test data in the form of a datastep!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wiothout seeing the data we can't say, maybe there is a space or an unprintable value in your string, maybe your using the wrong data who knows. &amp;nbsp;This is why we ask for test data so we can see it as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353680#M82572</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-26T13:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353682#M82573</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(left(put(UB_92_REV_CD_GP_1,4.)),1,2) = "17" then REV_CHAR_GP_1 = "170 TEST";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;assuming that UB_92_REV_CD_GP_1 is in fact numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353682#M82573</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-26T13:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353725#M82581</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43822"&gt;@Wolverine&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I'm using SAS 9.4.&amp;nbsp; I'm trying to collapse approximately &lt;STRONG&gt;1000 codes into 77 groups&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Looks like a very likely candidate for a custom format, and with codes that look like that a MULTILABEL might even be of help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since: "UB_92_REV_CD_GP_1 variable is 4-digit numeric"&lt;/P&gt;
&lt;P&gt;a numeric format would let you use a range:&lt;/P&gt;
&lt;P&gt;Proc format;&lt;/P&gt;
&lt;P&gt;value somefmtname&lt;/P&gt;
&lt;P&gt;170-179 = 'Text I want associated with these variable values'&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;Then use the format with the variable in procedures to get the desired group and text label. No extra varaibles needed. And you don't get into the ugly "numerics that start with character" stuff.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 14:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/353725#M82581</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-26T14:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/355218#M83200</link>
      <description>&lt;P&gt;This works and was easy to incorporate into my existing syntax.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 12:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/355218#M83200</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2017-05-02T12:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using colon to find all numeric values beginning with a specified number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/355219#M83201</link>
      <description>&lt;P&gt;The frequency output is getting sent to an Excel output file, and unfortunately the assigned formats don't survive that process.&amp;nbsp; That's why I'm recoding into a string variable.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 12:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-colon-to-find-all-numeric-values-beginning-with-a/m-p/355219#M83201</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2017-05-02T12:23:49Z</dc:date>
    </item>
  </channel>
</rss>

