<?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: Need Help with Vertical processing in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680568#M205699</link>
    <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data HAVE;
  input TIME PRICE ACTION $; 
  retain BUYOBS; 
  if ^BUYOBS &amp;amp; ACTION='buy' then BUYOBS = _N_ ; 
  if BUYOBS &amp;lt; _N_ &amp;lt; BUYOBS+5 then ACTION='hold';
  if _N_ = BUYOBS+4 then BUYOBS=0;
cards;
1 5 buy
2 2 buy
3 8 c
4 10 sell 
5 12 buy
6 5 sell
7 2 buy
8 8 c
9 10 sell 
10 12 buy
11 8 c
12 10 sell 
13 12 buy
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.HAVE" width="155px" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col" width="23.6364px"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="40px"&gt;TIME&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="40px"&gt;PRICE&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="50px"&gt;ACTION&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;1&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;1&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;2&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;3&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;3&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;4&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;4&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;5&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;6&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;6&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;sell&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;7&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;7&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;8&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;9&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;9&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;10&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;11&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;11&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;12&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;sell&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;13&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;13&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&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>Mon, 31 Aug 2020 22:03:46 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-08-31T22:03:46Z</dc:date>
    <item>
      <title>Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680558#M205694</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me with the following dataset processing:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;time price action;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;10&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;11&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;13&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to pickup the first buy signal and then write 'hold' for four observations below it irrespective of the following signals. Desired output should look like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;time price action;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp;hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp;hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp; &amp;nbsp; hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp; &amp;nbsp; hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;10&amp;nbsp; &amp;nbsp; 12&amp;nbsp; hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;11&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; hold&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp;sell&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;13&amp;nbsp; &amp;nbsp; 12&amp;nbsp; &amp;nbsp;buy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am having trouble with this kind of vertical&amp;nbsp;processing in SAS. I guess an alternate way would be to transpose&amp;nbsp;the data to wide and work with it. I would love to see if this can be achieved without data transformation using loops?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks a lot,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Bhupesh&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 21:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680558#M205694</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-08-31T21:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680568#M205699</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data HAVE;
  input TIME PRICE ACTION $; 
  retain BUYOBS; 
  if ^BUYOBS &amp;amp; ACTION='buy' then BUYOBS = _N_ ; 
  if BUYOBS &amp;lt; _N_ &amp;lt; BUYOBS+5 then ACTION='hold';
  if _N_ = BUYOBS+4 then BUYOBS=0;
cards;
1 5 buy
2 2 buy
3 8 c
4 10 sell 
5 12 buy
6 5 sell
7 2 buy
8 8 c
9 10 sell 
10 12 buy
11 8 c
12 10 sell 
13 12 buy
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.HAVE" width="155px" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col" width="23.6364px"&gt;Obs&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="40px"&gt;TIME&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="40px"&gt;PRICE&lt;/TH&gt;
&lt;TH class="l header" scope="col" width="50px"&gt;ACTION&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;1&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;1&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;2&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;3&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;3&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;4&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;4&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;5&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;6&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;6&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;5&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;sell&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;7&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;7&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;2&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;8&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;9&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;9&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;10&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;11&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;11&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;8&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;hold&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;12&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;10&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;sell&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row" width="23.6364px"&gt;13&lt;/TH&gt;
&lt;TD width="40px" class="r data"&gt;13&lt;/TD&gt;
&lt;TD width="40px" class="r data"&gt;12&lt;/TD&gt;
&lt;TD width="50px" class="l data"&gt;buy&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&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>Mon, 31 Aug 2020 22:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680568#M205699</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-08-31T22:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680583#M205704</link>
      <description>&lt;P&gt;You need to do 2 things:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;maintain a countdown starting at 4 whenever you detect a "first buy".&lt;/LI&gt;
&lt;LI&gt;detect "first buy" as any 'buy' following something other than a buy - the lag function is the thing here.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input time price action $; 
cards;
1 5 buy
2 2 buy
3 8 
4 10 sell 
5 12 buy
6 5 sell
7 2 buy
8 8 
9 10 sell 
10 12 buy
11 8 
12 10 sell 
13 12 buy
run;

data want (drop=_:);
  set have;
  retain _countdown 0;
  if _countdown&amp;gt;0 then do;
    action='hold';
    _countdown+(-1);
  end;
    if action='buy' and lag(action)^='buy' and not (_countdown&amp;gt;0) then _countdown=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;edit note: removed the erroneous:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  else if action='buy' and lag(action)^='buy' then _countdown=4;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Sep 2020 00:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680583#M205704</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-01T00:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680687#M205766</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input time price action $; 
cards;
1 5 buy
2 2 buy
3 8 
4 10 sell 
5 12 buy
6 5 sell
7 2 buy
8 8 
9 10 sell 
10 12 buy
11 8 
12 10 sell 
13 12 buy
;
run;

data temp;
 set have;
 if action='buy';
 keep time action;
run;
data temp1;
 set temp;
 retain t;
 if _n_=1 then do;t=time;output;end;
 if time&amp;gt;t+4 then do;t=time;output;end;
 keep t;
run;
data temp2;
 set temp1;
 do time=t+1 to t+4;
  output;
 end;
 keep time;
run;
data want;
 if _n_=1 then do;
  declare hash h(dataset:'temp2');
  h.definekey('time');
  h.definedone();
 end;
set have;
if h.check()=0 then action='hold';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Sep 2020 13:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680687#M205766</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-01T13:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680848#M205864</link>
      <description>Hi Chris,&lt;BR /&gt;&lt;BR /&gt;This is an excellent solution.&lt;BR /&gt;Will this code work in a similar fashion with slight modification?&lt;BR /&gt;&lt;BR /&gt;retain BUYOBS 0;&lt;BR /&gt;if BUYOBS = 0 &amp;amp; ACTION='buy' then BUYOBS = _N_ ;&lt;BR /&gt;if BUYOBS &amp;lt; _N_ &amp;lt; BUYOBS+5 then ACTION='hold';&lt;BR /&gt;if _N_ = BUYOBS+4 then BUYOBS=0;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Bhupesh</description>
      <pubDate>Wed, 02 Sep 2020 02:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680848#M205864</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-09-02T02:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680850#M205866</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;Will this code work in a similar fashion with slight modification?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes it should.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 02:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680850#M205866</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-09-02T02:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680853#M205869</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/126332"&gt;@bhupeshpanwar&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to be absolutely sure is to first run Chris' version of the code, then run your version, and then to run a Proc Compare on your results.&amp;nbsp; If the results are a 100% match you have a pretty good assurance that in fact the new version of the code is working the same as the first version.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we name the dataset from Chris' version "Have" and the dataset from your version "Have2," a simple Proc Compare would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC	COMPARE	BASE	=	Have
				COMPARE	=	Have2;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The results after running look like this:&lt;/P&gt;
&lt;PRE&gt;Observation Summary                                                                                                          
                                                                                                                             
Observation      Base  Compare                                                                                               
                                                                                                                             
First Obs           1        1                                                                                               
Last  Obs          13       13                                                                                               
                                                                                                                             
Number of Observations in Common: 13.                                                                                        
Total Number of Observations Read from WORK.HAVE: 13.                                                                        
Total Number of Observations Read from WORK.HAVE2: 13.                                                                       
                                                                                                                             
Number of Observations with Some Compared Variables Unequal: 0.                                                              
Number of Observations with All Compared Variables Equal: 13.                                                                
                                                                                                                             
NOTE: No unequal values were found. All values compared are exactly equal.  &lt;/PRE&gt;
&lt;P&gt;The key phrase I look for is in the Observation Summary:&amp;nbsp; "&lt;STRONG&gt;All values compared are exactly equal&lt;/STRONG&gt;."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 03:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680853#M205869</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-02T03:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680877#M205886</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;your solution works well even without the lag(action)^='buy' comparison. Why do we need that? Can you please check the code below as it works as intended for me? Thanks for your help.&lt;BR /&gt;&lt;BR /&gt;data want (drop=_:);&lt;BR /&gt;set have;&lt;BR /&gt;retain _countdown 0;&lt;BR /&gt;if _countdown&amp;gt;0 then do;&lt;BR /&gt;action='hold';&lt;BR /&gt;_countdown+(-1);&lt;BR /&gt;end;&lt;BR /&gt;if action='buy' and countdown=0 then _countdown=4;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Wed, 02 Sep 2020 06:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/680877#M205886</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-09-02T06:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681027#M205941</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/126332"&gt;@bhupeshpanwar&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're right - the use of lag is superfluous, and using countdown works fine, and is less busy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question:&amp;nbsp; What do you want to do if you have a sequence of, say, 7 buys. Your (and my) program would convert &lt;/P&gt;
&lt;PRE&gt;           buy, buy, buy, buy, buy, buy, buy&lt;/PRE&gt;
&lt;P&gt;into&lt;/P&gt;
&lt;PRE&gt;           buy, hold,hold,hold,hold,buy, hold&lt;/PRE&gt;
&lt;P&gt;The sixth element is a buy, but it is not the first buy.&amp;nbsp; Do you really want to treat it as the start of another buy-and-hold series?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 15:08:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681027#M205941</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-02T15:08:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681151#M206000</link>
      <description>Thanks for the confirmation.&lt;BR /&gt;Yes, this is the correct output. The sixth element in your case should be the start of a new buy hold series.&lt;BR /&gt;&lt;BR /&gt;Bhupesh</description>
      <pubDate>Wed, 02 Sep 2020 20:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681151#M206000</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-09-02T20:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need Help with Vertical processing in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681198#M206023</link>
      <description>&lt;P&gt;Thank you for all the solutions. All three solutions posted work really well. I will accept Chris as a solution since he was the one to post it first. I leaned a lot from all of you. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 01:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-Help-with-Vertical-processing-in-SAS/m-p/681198#M206023</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-09-03T01:31:40Z</dc:date>
    </item>
  </channel>
</rss>

