<?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: How to create a Flag Variable,  Based on the variable contains  Certain words? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798225#M313811</link>
    <description>&lt;P&gt;if you have like 50 different words to look for, they are stored in a table of some sort right?&lt;/P&gt;</description>
    <pubDate>Wed, 23 Feb 2022 19:50:55 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-02-23T19:50:55Z</dc:date>
    <item>
      <title>How to create a Flag Variable,  Based on the variable contains  Certain words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798224#M313810</link>
      <description>&lt;P&gt;I am looking to create a flag variable ="Y" in my example&amp;nbsp; if my "aetype" variable contains&amp;nbsp; any of the words (Nausea or headache) in it. I am little aware of using "FIND" or "INDEX" or "FINDW". So I have to write condition for every word? because I have alike 50 different words if those are present in "aetype" then&amp;nbsp; I need flag="Y". Is there any&amp;nbsp; efficient way? Thank you for your suggestions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data adverse;
	Input Sid visit$ aetype$ severity$;
	datalines;
101 v1 rashes mild
102 v2 vomitings moderate
103 v3 headache severe
;
run;

data adverse1;
length aetype $30.;
set adverse;
if aetype= "rashes" then aetype= 'rashes,Nausea';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1645645643957.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/68782iEDF089295ECCFEB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1645645643957.png" alt="SASuserlot_0-1645645643957.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 19:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798224#M313810</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-02-23T19:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Flag Variable,  Based on the variable contains  Certain words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798225#M313811</link>
      <description>&lt;P&gt;if you have like 50 different words to look for, they are stored in a table of some sort right?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 19:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798225#M313811</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-02-23T19:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Flag Variable,  Based on the variable contains  Certain words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798227#M313813</link>
      <description>&lt;P&gt;I have the condition provided like 50 words ( which I have the list). they are expecting those words will be in aetype variable as single word or combination with others. FYI: I created the adverse1 dataset, so that I can have the word in combination ( Nausea). My interest words are Nausea and headache.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 19:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798227#M313813</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-02-23T19:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Flag Variable,  Based on the variable contains  Certain words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798263#M313822</link>
      <description>&lt;P&gt;One way is a temporary array and then you search with those.&lt;/P&gt;
&lt;PRE&gt;data adverse1;
   length aetype $30.;
   set adverse;
   array words (2) $ 15 _temporary_  ('Nausea', 'headache');
   do i= 1 to dim(words);
      if findw(aetype,strip(words[i]),' ','i')&amp;gt;0 then do;
         flag='Y';
         leave;
      end;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;temporary arrays do not have the values written to the output data set. You specify the number of elements, 2 in this case and for character values you use $ and a number to set the maximum number of characters to store, the keyword _temporary_ and then a list of the values in quotes for character as usual.&lt;/P&gt;
&lt;P&gt;The Dim function returns the number of elements defined in the array so you can search for each word in order from left to right as defined in the array statement.&lt;/P&gt;
&lt;P&gt;You say you are familiar with Find and Findw so no details though you may not realize that you may need to strip (remove) leading and trailing blanks for the comparison. The LEAVE statement tells the loop to stop when encountered. So if you want to stop when the first word in the list is found then issue a leave.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This used findw so "headaches" would not match "headache" in the search list. Similar behavior could be done with FIND or INDEX or INDEXW per the syntax.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 21:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798263#M313822</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-23T21:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a Flag Variable,  Based on the variable contains  Certain words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798264#M313823</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;. I will try this as soon as I can. I will let you know if I encounter any issues. thanks for explaining about the problems with other functions.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 22:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-Flag-Variable-Based-on-the-variable-contains/m-p/798264#M313823</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-02-23T22:01:19Z</dc:date>
    </item>
  </channel>
</rss>

