<?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: Search and create column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709574#M218233</link>
    <description>&lt;P&gt;Are these character columns? And is the value to be searched for always "123"?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Jan 2021 09:32:11 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-01-06T09:32:11Z</dc:date>
    <item>
      <title>Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709570#M218231</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy new year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&lt;SPAN&gt;I got multiple columns named “b_yyww” specifying the year and week, eg. b_0003 and b_9751. The columns are arranged in order b_9601 to b_1352.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&lt;SPAN&gt;I have another column “date of event” specifying the date of at given event (ddmmyy).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&lt;SPAN&gt;I want to search for a specific value “123” in the “b_yyww” columns and create two new columns: “123 before event” and “123 after event” specifying whether 123 occurred before/after the event “yes”/”no”.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;Is this possible?&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="font-weight: 400;"&gt;/MM&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709570#M218231</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-01-06T09:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709574#M218233</link>
      <description>&lt;P&gt;Are these character columns? And is the value to be searched for always "123"?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709574#M218233</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-06T09:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709577#M218236</link>
      <description>&lt;P&gt;I am not sure what you mean by character columns, sorry.&lt;/P&gt;
&lt;P&gt;The value to be searched for are four different combinations of a 3-digit number (123, 000, 100, and 110).&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:47:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709577#M218236</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-01-06T09:47:31Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709579#M218237</link>
      <description>&lt;P&gt;So a simplified version of your data looks like this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input b_9601-b_9606 date_event :date9.;
format date_event date9.;
datalines;
999 123 888 777 666 123 01Mar1996
999 123 888 777 666 555 01Apr1996
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709579#M218237</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-06T09:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709580#M218238</link>
      <description>&lt;P&gt;Exactly!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709580#M218238</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-01-06T09:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709582#M218240</link>
      <description>&lt;P&gt;See if you can use this as a template. Feel free to ask &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input b_9601-b_9606 date_event :date9.;
format date_event date9.;
datalines;
999 123 888 777 666 123 01Mar1996
999 123 888 777 666 555 01Apr1996
;

data want;
   set have;
   array b b_:;
   _123before = 'No ';
   _123after = 'No ';
   do over b;
      dt = input(compress(vname(b),, 'kd'), yymmn4.);
      if dt &amp;lt; date_event and b = 123 then _123before = 'Yes';
      if dt &amp;gt; date_event and b = 123 then _123after = 'Yes';
   end;
   drop dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;b_9601 ......... b_9606  date_event _123before _123after 
999 123 888 777 666 123  01MAR1996  Yes        Yes 
999 123 888 777 666 555  01APR1996  Yes        No &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709582#M218240</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-06T10:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709585#M218241</link>
      <description>&lt;P&gt;b_9601 is yyww (year and week). I tried changing yymmn4 to yywwn4, but get error when I do this.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709585#M218241</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-01-06T10:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709589#M218242</link>
      <description>&lt;P&gt;I used weekv8 instead, and it seems to be working! Thank you!!!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709589#M218242</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2021-01-06T10:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709591#M218244</link>
      <description>&lt;P&gt;Ok. Try this instead&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input b_9601-b_9606 date_event :date9.;
format date_event date9.;
datalines;
999 123 888 777 666 123 01Mar1996
999 123 888 777 666 555 01Apr1996
;

data want;
   set have;
   array b b_:;
   _123before = 'No ';
   _123after = 'No ';
   do over b;
      dt = input(cats(substr(compress(vname(b),, 'kd'), 1, 2), "W", 
                      substr(compress(vname(b),, 'kd'), 3, 2)), weeku5.);
      if dt &amp;lt; date_event and b = 123 then _123before = 'Yes';
      if dt &amp;gt; date_event and b = 123 then _123after = 'Yes';
   end;
   drop dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709591#M218244</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-06T10:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Search and create column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709592#M218245</link>
      <description>&lt;P&gt;Great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Glad you found your answer.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 10:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-and-create-column/m-p/709592#M218245</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-06T10:50:23Z</dc:date>
    </item>
  </channel>
</rss>

