<?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: Trying to Using if and Like together in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637319#M21450</link>
    <description>&lt;P&gt;LIKE can only be used in a Where expression in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data want;
   set sashelp.class;
   where name like 'J%';
run;&lt;/PRE&gt;
&lt;P&gt;You might try&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if upcase(column1) =: "SPEC"
       then new_column = "Specialty";
run;&lt;/PRE&gt;
&lt;P&gt;The =: is "begins with".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also number of other functions to search text like FIND, FINDW, INDEX, INDEXW and the PRX functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Apr 2020 17:56:50 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-03T17:56:50Z</dc:date>
    <item>
      <title>Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637313#M21448</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I am trying to use the “if” and “like” statement to create a new column called “new_column” based on the character values of “column1”. But I get an error (see below). I am trying to use the “Like” statement but does not seem to work with “if” statement. &lt;BR /&gt;Please advice&amp;nbsp; on an alternative approach. Thanks!&lt;/P&gt;
&lt;P&gt;Column1 is a character column and I am trying to create another character column called “column1” based on column1 values values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;---current code---&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if upcase(column1) like "SPEC%"&lt;BR /&gt;then new_column = "Specialty";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get the following error:&lt;/P&gt;
&lt;P&gt;Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, ;, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, &lt;BR /&gt;2 The SAS System 11:46 Friday, April 3, 2020&lt;/P&gt;
&lt;P&gt;IN, LE, LT, MAX, MIN, NE, NG, NL, NOT, NOTIN, OR, THEN, ^, ^=, |, ||, ~, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 17:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637313#M21448</guid>
      <dc:creator>ubshams</dc:creator>
      <dc:date>2020-04-03T17:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637315#M21449</link>
      <description>&lt;P&gt;LIKE works in PROC SQL. It does not work in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To fix this, try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if upcase(column1) =: "SPEC" then new_column = "Specialty";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The =: operator (note the colon after the equal sign) finds cases where upcase(column1) starts with SPEC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, please do not disconnect the log from the code. Copy the log (including the code and the warnings and error messages) with nothing chopped out and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon. This preserves the formatting of the log and makes it more readable and more meaningful. DO NOT SKIP THIS STEP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 17:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637315#M21449</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-03T17:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637319#M21450</link>
      <description>&lt;P&gt;LIKE can only be used in a Where expression in a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data want;
   set sashelp.class;
   where name like 'J%';
run;&lt;/PRE&gt;
&lt;P&gt;You might try&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if upcase(column1) =: "SPEC"
       then new_column = "Specialty";
run;&lt;/PRE&gt;
&lt;P&gt;The =: is "begins with".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are also number of other functions to search text like FIND, FINDW, INDEX, INDEXW and the PRX functions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 17:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637319#M21450</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-03T17:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637329#M21452</link>
      <description>&lt;P&gt;Thanks. But the values in&amp;nbsp; column1 are like this:&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec_Text5_Text6&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec2_Text5_Text6&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec6_Text5_Text6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the ":=" is usfeful, but not in this case. Is there a CONTAINS OR LIKE equivalent I can use with an "IF" statement to create a new column?&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 18:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637329#M21452</guid>
      <dc:creator>ubshams</dc:creator>
      <dc:date>2020-04-03T18:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637330#M21453</link>
      <description>Yes. &lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;Try INDEX, INDEXW, FIND, or FINDW .</description>
      <pubDate>Fri, 03 Apr 2020 18:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637330#M21453</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-03T18:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637338#M21454</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185449"&gt;@ubshams&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. But the values in&amp;nbsp; column1 are like this:&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec_Text5_Text6&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec2_Text5_Text6&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Text1_Text2_Text3_Spec6_Text5_Text6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the ":=" is usfeful, but not in this case. Is there a CONTAINS OR LIKE equivalent I can use with an "IF" statement to create a new column?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may need to actually provide real, or more realistic example values. Your initial LIKE example would "work" only if the string starts with "SPEC".&lt;/P&gt;
&lt;PRE&gt;data have;
    input column1 $;
datalines;
Text1
Spec_
Cspec
x_SPEC_
;
run;
data want;
   set have;
   where upcase(column1) like "SPEC%";
   new_column = "Specialty";
run;&lt;/PRE&gt;
&lt;P&gt;Only the value that starts with Spec is kept.&lt;/P&gt;
&lt;P&gt;Which is why I translated your example like to =: .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2020 19:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637338#M21454</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-03T19:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to Using if and Like together</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637362#M21458</link>
      <description>&lt;P&gt;As mentioned by others use a function like FIND or INDEX and for more complex logic you could use PRXMATCH&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if find(upcase(column1),"SPEC")
then new_column = "Specialty";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Apr 2020 21:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Trying-to-Using-if-and-Like-together/m-p/637362#M21458</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-04-03T21:43:48Z</dc:date>
    </item>
  </channel>
</rss>

