<?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 append two observations based on a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428238#M105711</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input text $1-21;
cards;
Hello There
Oh! No
Hello World
See You Guys
Oh! Yes
run;
data want;
  merge have
        have (firstobs=2 rename=(text=text_next));
  if text_next =: 'Oh!' then text=catx(' ',text,text_next);
  if not(text=:'Oh!');
  drop text_next;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 17 Jan 2018 01:24:51 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-01-17T01:24:51Z</dc:date>
    <item>
      <title>how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428202#M105693</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to append two rows one after another based on a condition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data test1;

input x $1-15;
cards;
Hello There
Oh! No
Hello World
See You Guys
Oh! Yes
;
run;

data test2;
set test1;
if findw(cat,'DATA',1,'.','i')  then 
do 
Concat_var1=_n_;

end;
Concat_var2=Concat_var1-1;
if scan(cat,1)='DATA'  and Concat_var1 eq . then Concat_var1=Concat_var2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected Output :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever the "Oh!" word encounters it should be appended with just to prior row value. Like for example in the output should be like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Hello There Oh! No
Hello World
See You&amp;nbsp;Guys Oh! Yes&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;Please help if possible.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 22:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428202#M105693</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2018-01-16T22:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428205#M105694</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data test1;

input x $1-15;
cards;
Hello There
Oh! No
Hello World
See You Guys
Oh! Yes
;
run;

data want;
set test1;
length t $50;
k=lag(x);
if find(x,'Oh!')&amp;gt;0 then do; t=catx(' ',k,x);output;end;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 22:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428205#M105694</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T22:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428206#M105695</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set test1;
length t $50;
k=lag(x);
if find(x,'Oh!')&amp;gt;0 then do; t=catx(' ',k,x);output;end;
else if find(k,'Oh!')&amp;gt;0 then do; t=x; output;end;
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Jan 2018 22:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428206#M105695</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T22:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428215#M105699</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205" target="_self"&gt;novinosrin&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks for the quick reply, but it's deleting the "Hello world" line from the output. That is also needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 23:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428215#M105699</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2018-01-16T23:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428216#M105700</link>
      <description>&lt;P&gt;Yes, I realized that. So, posted another one. Did you test the most recent post of mine?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 23:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428216#M105700</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-16T23:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428221#M105701</link>
      <description>&lt;P&gt;Because of the need to output when Oh is not present on the next line ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;length x $ 30;&lt;/P&gt;
&lt;P&gt;merge test1 test1 (firstobs=2 rename=(x=y));&lt;/P&gt;
&lt;P&gt;if index(x, 'Oh!') then delete;&lt;/P&gt;
&lt;P&gt;if index(y, 'Oh!') then x = catx(' ', x, y);&lt;/P&gt;
&lt;P&gt;drop y;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't test it right now, but it looks about right.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2018 23:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428221#M105701</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-16T23:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428238#M105711</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input text $1-21;
cards;
Hello There
Oh! No
Hello World
See You Guys
Oh! Yes
run;
data want;
  merge have
        have (firstobs=2 rename=(text=text_next));
  if text_next =: 'Oh!' then text=catx(' ',text,text_next);
  if not(text=:'Oh!');
  drop text_next;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Jan 2018 01:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428238#M105711</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-01-17T01:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428255#M105719</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_self"&gt;mkeintz&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;I am looking for a generic solution. The firstobs=2 is actually limiting the data making it limited to the scenario specific. If I have more than 1000 records then it might not work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Hope you can understand.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 05:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428255#M105719</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2018-01-17T05:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428257#M105721</link>
      <description>&lt;P&gt;Hi Astounding,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply. The firstobs=2 is actually limiting the data. Like in the real scenario, suppose the "Oh!" word is not starting at row no.2 and think if there would be&amp;nbsp; more than 1000 of records then we might not open the dataset each time to look at, in order to know about the "Oh!" word starting row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking for a generic solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 05:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428257#M105721</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2018-01-17T05:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428383#M105772</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13220"&gt;@rajdeep&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Having had time to test this, it works just fine.&amp;nbsp; FIRSTOBS=2 just sets the starting point ... which observation is the first one to bring in.&amp;nbsp; But SAS brings in the next one, then the next one, etc.&amp;nbsp; It should be easy enough for you to test the code on a small number of observations to be sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As illustrated&amp;nbsp; in the &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;post, it makes a difference whether you are looking for "Oh!" at the beginning of the next&amp;nbsp;line, or "Oh!" anywhere within the next line.&amp;nbsp; My solution looks for "Oh!" anywhere within the next line.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 14:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428383#M105772</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-17T14:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428575#M105827</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13220"&gt;@rajdeep&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What do you mean by "If I have more than 1000 records then it might not work."?&amp;nbsp;&amp;nbsp; I presume you tested the program I provided.&amp;nbsp; It worked for 5 records.&amp;nbsp; Why would it fail with 1,000?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 19:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428575#M105827</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-01-17T19:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to append two observations based on a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428657#M105853</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461" target="_self"&gt;mkeintz&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks for your help. I am sorry I was trying something wrong. Now it's working. Thanks a lot for your help. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Cheers.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jan 2018 23:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-append-two-observations-based-on-a-condition/m-p/428657#M105853</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2018-01-17T23:37:14Z</dc:date>
    </item>
  </channel>
</rss>

