<?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: Use of 'case when + contains/like' when i have number such as 50 and 500 in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846722#M41797</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input CPP $40.;
cards;
blabla DP50_L
blablablu DP 50 L
ble DP50
blx DP50_500 
blibli DP500_L
bliblibla DP 500 L
bliblible DP500
blublu DP500 50
;

proc sql;
select cpp,case when cpp like '%50%' then 
case when substr(cpp,find(cpp,'50'),3)='500' then 500 else 50 end
           else . end as want 
 from have;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Nov 2022 02:05:07 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-11-29T02:05:07Z</dc:date>
    <item>
      <title>Use of 'case when + contains/like' when i have number such as 50 and 500</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846622#M41789</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;i m trying to create a new column (using case when and contains/like) depending on the context of another string column, but i find it troublesome when it comes to containing numbers such as 50 and 500 for example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HAVE DATASET&lt;/P&gt;
&lt;P&gt;CPP&lt;/P&gt;
&lt;P&gt;blabla DP50_L&lt;/P&gt;
&lt;P&gt;blablablu DP 50 L&lt;/P&gt;
&lt;P&gt;ble DP50&lt;/P&gt;
&lt;P&gt;blx DP50_500&amp;nbsp;&lt;/P&gt;
&lt;P&gt;blibli DP500_L&lt;/P&gt;
&lt;P&gt;bliblibla DP 500 L&lt;/P&gt;
&lt;P&gt;bliblible DP500&lt;/P&gt;
&lt;P&gt;blublu&amp;nbsp;DP500 50&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT DATASET&lt;/P&gt;
&lt;P&gt;CPP&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SPEED&lt;/P&gt;
&lt;P&gt;blabla DP50_L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;blablablu DP 50 L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;50&lt;/P&gt;
&lt;P&gt;ble DP50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;blx DP50_500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 50&lt;/P&gt;
&lt;P&gt;blibli DP500_L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/P&gt;
&lt;P&gt;bliblibla DP 500 L&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;
&lt;P&gt;bliblible DP500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;
&lt;P&gt;blublu&amp;nbsp;DP500 50&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;500&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a result, i have faulty classification. What is the proper way to create the column of the example above?&lt;/P&gt;
&lt;P&gt;Thanks alot for your time and insights!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 15:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846622#M41789</guid>
      <dc:creator>Primohunter</dc:creator>
      <dc:date>2022-11-28T15:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Use of 'case when + contains/like' when i have number such as 50 and 500</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846628#M41790</link>
      <description>&lt;P&gt;Data cleansing is a cumbersome job, and sometimes it's hard to get it 100&amp;amp; perfect.&lt;/P&gt;
&lt;P&gt;My take would to find starting position of string "DP", substring the following 4 characters, remove any non numerical character, and then input that result to a numerical column.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 15:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846628#M41790</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-11-28T15:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Use of 'case when + contains/like' when i have number such as 50 and 500</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846629#M41791</link>
      <description>&lt;P&gt;I think there is some ambiguity in your sample WANT.&amp;nbsp; Namely, what is the rule you intend to apply to get the speed values?&amp;nbsp; In particular, is it the first number in the text of CPP?&amp;nbsp; Is it the first number after the string 'DP'?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's the earlier (first number in the text of CPP):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input cpp $char25. ;
datalines;
blabla DP50_L
blablablu DP 50 L
ble DP50
blx DP50_500 
blibli DP500_L
bliblibla DP 500 L
bliblible DP500
blublu DP500 50
run;

data want;
  set have;
  *find position of first numeric character,  call it _char1 ;
  _char1=anydigit(cpp);

  *generate substring length until first non-numeric character after _char1, call it _length;
  _length=notdigit(substr(cpp,_char1))-1;

  *Read that substring into a numeric variable;
  speed=input(substr(cpp,_char1,_length),best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited note:&amp;nbsp; This works only if the numeric value is a non-negative integer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2022 15:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846629#M41791</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-11-28T15:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: Use of 'case when + contains/like' when i have number such as 50 and 500</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846722#M41797</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input CPP $40.;
cards;
blabla DP50_L
blablablu DP 50 L
ble DP50
blx DP50_500 
blibli DP500_L
bliblibla DP 500 L
bliblible DP500
blublu DP500 50
;

proc sql;
select cpp,case when cpp like '%50%' then 
case when substr(cpp,find(cpp,'50'),3)='500' then 500 else 50 end
           else . end as want 
 from have;
quit;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 02:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-of-case-when-contains-like-when-i-have-number-such-as-50-and/m-p/846722#M41797</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-29T02:05:07Z</dc:date>
    </item>
  </channel>
</rss>

