<?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: Help with findw in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868715#M343178</link>
    <description>&lt;P&gt;Thanks for your quick response! One flag variable to capture all these cases without having to coping them all in the findw statement or a similar one.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Apr 2023 20:35:37 GMT</pubDate>
    <dc:creator>ama220</dc:creator>
    <dc:date>2023-04-08T20:35:37Z</dc:date>
    <item>
      <title>Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868713#M343176</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am trying to create a flag variable for certain values in a string variable. I tried the &lt;STRONG&gt;“&lt;/STRONG&gt;findw” statement but is not specific enough to capture certain same values as shown below without having to use endless number of entries. Any idea how I can a write a brief code that would capture cases as highlighted without having to put accompanying semicolon, or question marks?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If findw(dose, "") or findw(dose, "")&amp;nbsp; then dose_3_months = 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;? other frequency:once every 3 month;other route:inject?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;? other frequency:q3months ;?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;? other frequency:q3months;?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;200 units?every 3 months?head, neck, and shoulders&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;every 3 months?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;every 3 months?given into/under the skin&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;every 3 months?head/neck injections&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ama220_0-1680985268812.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82426i0E108EC826896740/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ama220_0-1680985268812.png" alt="ama220_0-1680985268812.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 20:23:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868713#M343176</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-04-08T20:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868714#M343177</link>
      <description>&lt;P&gt;I'm thinking that the goal has not been clearly explained. Is the goal to find which text strings contain&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;every 3 months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but not those that contain&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;q3months&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want string that contain either of those two strings? If so, please provide strings that don't contain either so we can test our code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want something else?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 20:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868714#M343177</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-08T20:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868715#M343178</link>
      <description>&lt;P&gt;Thanks for your quick response! One flag variable to capture all these cases without having to coping them all in the findw statement or a similar one.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 20:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868715#M343178</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-04-08T20:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868716#M343179</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83909"&gt;@ama220&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your quick response! One flag variable to capture all these cases without having to coping them all in the findw statement or a similar one.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It is still not clear to me. When you say "all these cases", are there just the two, the purple and the light blue? Or are there more that would be considered a match? If so, explain what would be considered a match, and provide a data set with a large variety of cases that match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We also need in the data set some strings that are not considered a match (which was requested earlier, and I request it again).&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 21:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868716#M343179</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-08T21:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868717#M343180</link>
      <description>&lt;P&gt;Thanks for your help, all the examples I provided are a match: every three months or q3months. The challenge is the values are presented as shown in the example I shared so I am trying to shorten the code to capture these cases.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 21:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868717#M343180</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-04-08T21:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868718#M343181</link>
      <description>&lt;P&gt;Ok, I asked twice now for examples that don't match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;every three months or q3months.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is it really "every three months" or "every 3 months"??&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2023 21:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868718#M343181</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-08T21:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868723#M343183</link>
      <description>&lt;P&gt;It is not at all clear what you tried. FINDW() should work fine for your example strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $80.;
cards4;
? other frequency:once every 3 month;other route:inject?
? other frequency:q3months ;?
? other frequency:q3months;?
200 units?every 3 months?head, neck, and shoulders
every 3 months?
every 3 months?given into/under the skin
every 3 months?head/neck injections
;;;;

data want;
  set have;
  dose_3_months = findw(string,'every 3 month',' ;:?')
               or findw(string,'every 3 months',' ;:?')
               or findw(string,'q3months',' ;:?')
  ;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Apr 2023 22:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868723#M343183</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-08T22:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868726#M343185</link>
      <description>&lt;P&gt;Thanks! This seems to be the right way; just had an error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;findw(dose_vbm, (string,'every 3 month',' ;:?') or findw(string,'every 3 months',' ;&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;2223! :?') or findw(string,'q3months',' ;:?') then dose_vbm_freq = 'months' ;else&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: (, ), [, {.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 00:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868726#M343185</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-04-09T00:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868728#M343186</link>
      <description>&lt;P&gt;Is the name of your variable DOSE_VBM or is it called STRING like the variable in my example?&lt;/P&gt;
&lt;P&gt;Whichever name it is using you only include the variable once in each of the FINDW() calls. And you probably want to always search the same variable every time, otherwise I doubt the logic will work right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if findw(dose_vbm, 'every 3 month',' ;:?')
 or findw(dose_vbm,'every 3 months',' ;:?')
 or findw(dose_vbm,'q3months',' ;:?') 
then dose_vbm_freq = 'months' ;
else dose_vbm_freq  ='??????';
&lt;/CODE&gt;&lt;/PRE&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>Sun, 09 Apr 2023 01:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868728#M343186</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-09T01:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868748#M343189</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83909"&gt;@ama220&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I would recommend looking into using Regular Expression for such text parsing scenarios.&lt;/P&gt;
&lt;P&gt;I used&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; data step to create the have data set&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $80.;
cards4;
? other frequency:once every 3 month;other route:inject?
? other frequency:q3months ;?
? other frequency:q3months;?
200 units?every 3 months?head, neck, and shoulders
every 3 months?
every 3 months?given into/under the skin
every 3 months?head/neck injections
;;;;
run;

data want;
	set work.have;
	dose_x_months = ifn(prxmatch('/(every |q)?\d\s?months*/', string),1,0); /* This will search for various monthly frequencies rather than just 3 */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here are couple of useful links related to RegEx&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A title="Regular Expressions 101" href="https://regex101.com/" target="_blank" rel="noopener"&gt;Regular Expressions 101&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A title="Express Yourself! Regular Expressions vs SAS Text String Functions" href="https://www.lexjansen.com/pharmasug/2014/BB/PharmaSUG-2014-BB08.pdf" target="_blank" rel="noopener"&gt;Express Yourself! Regular Expressions vs SAS Text String Functions&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Sun, 09 Apr 2023 10:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868748#M343189</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2023-04-09T10:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868845#M343240</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $80.;
cards4;
? other frequency:once every 3 month;other route:inject?
? other frequency:q3months ;?
? other frequency:q3months;?
200 units?every 3 months?head, neck, and shoulders
every 3 months?
every 3 months?given into/under the skin
every 3 months?head/neck injections
;;;;

data want;
 set have;
 pid=prxparse('/every\s+\d+\s+month(s)?|q\d+month(s)?/io');
 if prxmatch(pid,string) then do;
  call prxsubstr(pid,string,p,l);
  want=substr(string,p,l);
 end;
drop pid p l;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Apr 2023 11:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/868845#M343240</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-04-10T11:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/869156#M343333</link>
      <description>&lt;P&gt;Thanks, unofratnely, I am still missing instances of flagging "month" instances in the character variable in question b/c my data is messy. The only thing that seems to work is using a data step and the index variable. Any idea of what would be a better command to use. I tried many things to no avail and given that I have other similar character variables to code, I need a better way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if index(dose_vbm,'month') &amp;gt; 0;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 16:56:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/869156#M343333</guid>
      <dc:creator>ama220</dc:creator>
      <dc:date>2023-04-11T16:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help with findw</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/869164#M343337</link>
      <description>Show a better example of your data where records are missed if you want further help with the code. &lt;BR /&gt;&lt;BR /&gt;As an FYI - ChatGPT will help you build regular expressions to find data. One of it's more useful features IMO.</description>
      <pubDate>Tue, 11 Apr 2023 17:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-findw/m-p/869164#M343337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-11T17:51:27Z</dc:date>
    </item>
  </channel>
</rss>

