<?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 check if a string value is within a variable's lagged values? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719418#M222750</link>
    <description>&lt;P&gt;Is it&amp;nbsp;necessary with a macro?&lt;/P&gt;</description>
    <pubDate>Mon, 15 Feb 2021 17:59:28 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-02-15T17:59:28Z</dc:date>
    <item>
      <title>How to check if a string value is within a variable's lagged values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719413#M222749</link>
      <description>&lt;P&gt;I am trying to write a macro that takes a 2 word input as well as a numeric value (to specify the range of lag) and outputs only the situations where the condition is met that the 2nd word appears at most 20 observations after the first word. The input table looks something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Word&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;toby&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;hot&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;cat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;drop&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if I call a macro %keywordsearch(phrase = hot drop, lagval = 1), it should return an empty table but if I call the macro with lagval = 2 or greater, it should return a table with a single row containing id = 15. How would I do this?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:56:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719413#M222749</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2021-02-15T17:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a string value is within a variable's lagged values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719418#M222750</link>
      <description>&lt;P&gt;Is it&amp;nbsp;necessary with a macro?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 17:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719418#M222750</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-15T17:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a string value is within a variable's lagged values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719420#M222752</link>
      <description>&lt;P&gt;I need the macro so that I can search for different words and with different ranges. But if you can do it without a macro, I can figure out how to adapt it to a macro.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2021 18:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719420#M222752</guid>
      <dc:creator>Ani7</dc:creator>
      <dc:date>2021-02-15T18:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to check if a string value is within a variable's lagged values?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719473#M222762</link>
      <description>&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create data */
data words ;
	input word $ ;
cards ;
toby
hot
cat
drop
;

data find ;
	retain
		/* counter and flag */
		cnt 0
		foundWord1 0
		/* parameters */
		word1 "hot" 
		word2 "drop" 
		lag 1 ;
	
	set words;
	/* add 1 to counter if first word has been found */
	if foundWord1=1 then do ;
		cnt=cnt+1 ;
	end ;
	/* set flag if you find word 1 */
	if word=word1 then do ;
		foundWord1=1 ;
	end ;
	/* for debugging */
	put word= cnt= word1= word2= lag= ;
	/* if find word2 and cnt&amp;lt;=lag then success */
	if word=word2 and cnt&amp;lt;=lag then do ;
		put "FOUND " cnt= word1= word2= ;
	end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Feb 2021 21:07:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-if-a-string-value-is-within-a-variable-s-lagged/m-p/719473#M222762</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-02-15T21:07:27Z</dc:date>
    </item>
  </channel>
</rss>

