<?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: DELETING PRECEDING RECORDS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525338#M142946</link>
    <description>&lt;P&gt;Please post the data in a usable form: as data-step with datalines statement, so that we have all variables exactly in the form you have them.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jan 2019 07:54:08 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2019-01-08T07:54:08Z</dc:date>
    <item>
      <title>DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525335#M142944</link>
      <description>&lt;P&gt;Spent a long time trying to figure out how it can be done. But failed. Let's say my dataset look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Sl.&lt;/U&gt;&amp;nbsp; &lt;U&gt;Return&lt;/U&gt;&amp;nbsp; &lt;U&gt;Conz&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 &amp;nbsp;&amp;nbsp; 4.5563&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;2 &amp;nbsp;&amp;nbsp; 4.8562&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;3 &amp;nbsp;&amp;nbsp; 0.0000&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4 &amp;nbsp;&amp;nbsp; 3.5879&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;5 &amp;nbsp;&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;6 &amp;nbsp;&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;7 &amp;nbsp;&amp;nbsp; 0.0000&amp;nbsp; missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;8 &amp;nbsp;&amp;nbsp; 0.0000&amp;nbsp; 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;9 &amp;nbsp;&amp;nbsp; 2.5879 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;10&amp;nbsp; 3.6879 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;11&amp;nbsp; 3.6869 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;12&amp;nbsp; 4.5859 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;13&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;14&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;15&amp;nbsp; 0.0000&amp;nbsp; missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;16&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;17&amp;nbsp; 0.0000&lt;/SPAN&gt;&amp;nbsp; missing&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;18&amp;nbsp; 0.0000&amp;nbsp; 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;19&amp;nbsp; 4.5879 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20&amp;nbsp; 3.5629 &amp;nbsp;missing&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This dataset is a result of a merge. Hence, Conz has missing values. Conz variable is a count of zero returns. I want to delete corresponding zero returns for Conz&amp;gt;= 4. So, row 5-8 and row 13-18 should get deleted.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can I achieve this???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Much thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 07:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525335#M142944</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-08T07:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525338#M142946</link>
      <description>&lt;P&gt;Please post the data in a usable form: as data-step with datalines statement, so that we have all variables exactly in the form you have them.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 07:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525338#M142946</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-01-08T07:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525339#M142947</link>
      <description>&lt;P&gt;Unfortunately, the dataset I have is huge one having more than 800k observations. There are 19 columns. I do not have the datalines. What I have described above is the problem which I need to solve. I am sorry; I cannot get how I can make it easy for you.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525339#M142947</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-08T08:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525340#M142948</link>
      <description>&lt;P&gt;You have to read and count observations until CONZ&amp;gt;=4 (or until you encounter end of data set have).&amp;nbsp; Then set a keep count as the original count-CONZ (if CONZ&amp;gt;=4)&amp;nbsp; or the original count otherwise.&amp;nbsp; Reread the original count, outputting only up to the keep count.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Sl  Return  Conz;
datalines;
 1  4.5563  .
 2  4.8562  .
 3  0.0000  1
 4  3.5879  .
 5  0.0000  .
 6  0.0000  .
 7  0.0000  .
 8  0.0000  4
 9  2.5879  .
10  3.6879  .
11  3.6869  .
12  4.5859  .
13  0.0000  .
14  0.0000  .
15  0.0000  .
16  0.0000  .
17  0.0000  .
18  0.0000  6
19  4.5879  .
20  3.5629  .
run;

data want (drop=_:);
  do _n=1 by 1 until (conz&amp;gt;=4 or end_of_have);
    set have end=end_of_have;
  end;
  if conz&amp;gt;=4 then _keep=_n-conz;
  else _keep=_n;
  do _j=1 to _n;  /*Now reread*/
    set have;      
    if _j&amp;lt;=_keep then output; /*and selectively output*/
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:01:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525340#M142948</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-08T08:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525341#M142949</link>
      <description>&lt;P&gt;According to your description, that's a simple where condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where return ne 0 or conz ne .;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use the same condition as a subsetting if in your merge data step.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525341#M142949</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-08T08:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525342#M142950</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/239423"&gt;@d6k5d3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Unfortunately, the dataset I have is huge one having more than 800k observations. There are 19 columns. I do not have the datalines. What I have described above is the problem which I need to solve. I am sorry; I cannot get how I can make it easy for you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Obviously, we do not need all the observations, just enough to test code, and mainly for having the structure of your dataset. That's quite easy to do, a tool for this is in my footnotes.&lt;/P&gt;
&lt;P&gt;Creating fake data for testing in a data step with datalines is one of THE essential skills you'll need, so learn that NOW.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525342#M142950</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-08T08:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525343#M142951</link>
      <description>If I write "return ne 0", I would lose all zero return observations, which I do not want.</description>
      <pubDate>Tue, 08 Jan 2019 08:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525343#M142951</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-08T08:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525346#M142952</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/239423"&gt;@d6k5d3&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If I write "return ne 0", I would lose all zero return observations, which I do not want.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PLEASE.READ.MY.WHOLE.POST. With diligence.&lt;/P&gt;
&lt;P&gt;My condition will remove only observations where return is zero AND conz is missing.&lt;/P&gt;
&lt;P&gt;Just test it.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525346#M142952</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-08T08:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525353#M142955</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the OP is worried about a sequence of 2 records with return=0 followed by a record with CONZ=2.&amp;nbsp; Although that situation is not in the sample date, I believe it is supposed to be kept.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 08:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525353#M142955</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-08T08:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525359#M142959</link>
      <description>Thank you very much! It works great! However, since I am a beginner, I am having some difficulty in getting the code. I wish I could understand:&lt;BR /&gt;what does it mean when you write _:, _n, _keep, _j (what's the significance of keeping an underscore. How is it different from _TYPE_ or _FREQ_? I don't know what I should search online to get an understanding of this.)&lt;BR /&gt;&lt;BR /&gt;What is happening when you write "do _n=1 by 1". You did not mention 'by' in "do _j=1 to _n".&lt;BR /&gt;&lt;BR /&gt;Much thanks once again!&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Jan 2019 09:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525359#M142959</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-08T09:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: DELETING PRECEDING RECORDS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525362#M142961</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the OP is worried about a sequence of 2 records with return=0 followed by a record with CONZ=2.&amp;nbsp; Although that situation is not in the sample date, I believe it is supposed to be kept.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, that's what happens when someone posts incomplete example data in unusable form. Maxim 42.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 09:40:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DELETING-PRECEDING-RECORDS/m-p/525362#M142961</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-01-08T09:40:20Z</dc:date>
    </item>
  </channel>
</rss>

