<?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 Extracting only when specific word exist in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887530#M39386</link>
    <description>Hi,&lt;BR /&gt;The ID column I have in the data is a character as shown below:&lt;BR /&gt;&lt;BR /&gt;ID&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;My question is, I want to create a new variable named ID2 for example and that new variable contain only values when the word “Sam” is present.&lt;BR /&gt;&lt;BR /&gt;So the new data set would be:&lt;BR /&gt;&lt;BR /&gt;ID ID2&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032 Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
    <pubDate>Wed, 02 Aug 2023 18:25:23 GMT</pubDate>
    <dc:creator>Rahim_221</dc:creator>
    <dc:date>2023-08-02T18:25:23Z</dc:date>
    <item>
      <title>Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887530#M39386</link>
      <description>Hi,&lt;BR /&gt;The ID column I have in the data is a character as shown below:&lt;BR /&gt;&lt;BR /&gt;ID&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;My question is, I want to create a new variable named ID2 for example and that new variable contain only values when the word “Sam” is present.&lt;BR /&gt;&lt;BR /&gt;So the new data set would be:&lt;BR /&gt;&lt;BR /&gt;ID ID2&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032 Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 02 Aug 2023 18:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887530#M39386</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2023-08-02T18:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887551#M39387</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH ID $ 25;
input ID $;
datalines;
Ram-2020
Ram-2024
Ram-20
Ram-Sam-3032
Ram-Bak-504
; 
run;

/* Use INDEX function */
data want;
LENGTH ID $ 25 ID2 $ 25;
 set have;
 ID2="";
 if index(ID,'Sam') then ID2=ID;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 20:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887551#M39387</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-08-02T20:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887555#M39388</link>
      <description>&lt;P&gt;You want to clearly define "word" as some functions in SAS allow to modify such definitions. Is your "word" always delimited by - before and after? Or might it be preceded by a space: "Ram Sam-3032" or spaces before and after: "Ram Sam 3032" or other characters:"Ram*Sam-3032" "Ram/Sam/3032" "Ram~Sam~3032" ? Are these matches?&lt;/P&gt;
&lt;P&gt;What if the value is "Ram-sam-3032" or "Ram-SAM-3032" or "Ram-sAM-3032". Are these matches with different case?&lt;/P&gt;
&lt;P&gt;What if "Sam" occurs as part of the value: "Ram-Samk-3032" is this a match?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436120"&gt;@Rahim_221&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi,&lt;BR /&gt;The ID column I have in the data is a character as shown below:&lt;BR /&gt;&lt;BR /&gt;ID&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;My question is, I want to create a new variable named ID2 for example and that new variable contain only values when the word “Sam” is present.&lt;BR /&gt;&lt;BR /&gt;So the new data set would be:&lt;BR /&gt;&lt;BR /&gt;ID ID2&lt;BR /&gt;Ram-2020&lt;BR /&gt;Ram-2024&lt;BR /&gt;Ram-20&lt;BR /&gt;Ram-Sam-3032 Ram-Sam-3032&lt;BR /&gt;Ram-Bak-504&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 20:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887555#M39388</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-02T20:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887566#M39389</link>
      <description>Thanks.&lt;BR /&gt;The word is alway delimited by - before and after but it may be Sam/SAM/sam.&lt;BR /&gt;Also, there won’t be a case when Sam is a part of another word like Samk as you asked!&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Aug 2023 20:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887566#M39389</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2023-08-02T20:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887571#M39390</link>
      <description>&lt;P&gt;I make it case insensitive now !&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
LENGTH ID $ 25;
input ID $;
datalines;
Ram-2020
Ram-2024
Ram-20
Ram-Sam-3032
Ram-Bak-504
; 
run;

/* Use INDEX function */
data want;
LENGTH ID $ 25 ID2 $ 25;
 set have;
 ID2="";
 if index(upcase(ID),'-SAM-') then ID2=ID;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;DIV id="ConnectiveDocSignExtentionInstalled" data-extension-version="1.0.4"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Aug 2023 20:38:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887571#M39390</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-08-02T20:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887577#M39393</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436120"&gt;@Rahim_221&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks.&lt;BR /&gt;The word is alway delimited by - before and after but it may be Sam/SAM/sam.&lt;BR /&gt;Also, there won’t be a case when Sam is a part of another word like Samk as you asked!&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What about strings that start or end with SAM?&lt;/P&gt;
&lt;P&gt;Perhaps you want to use the FINDW() function instead. Then you can tell it what characters are delimiters between words and to ignore the case of the letters in both strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if findw(id,'sam','-','i') then id2=id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the hyphens has to be there then add them to the search string and just use FIND() instead of FINDW().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if find(id,'-sam-','i') then id2=id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 20:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887577#M39393</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-02T20:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting only when specific word exist</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887586#M39394</link>
      <description>Thank you so much&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Aug 2023 21:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extracting-only-when-specific-word-exist/m-p/887586#M39394</guid>
      <dc:creator>Rahim_221</dc:creator>
      <dc:date>2023-08-02T21:08:07Z</dc:date>
    </item>
  </channel>
</rss>

