<?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: remove last 0 rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408098#M99527</link>
    <description>&lt;P&gt;&lt;SPAN&gt;All trailing zeroes.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2017 16:29:21 GMT</pubDate>
    <dc:creator>GeorgeSAS</dc:creator>
    <dc:date>2017-10-27T16:29:21Z</dc:date>
    <item>
      <title>remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408093#M99523</link>
      <description>&lt;PRE&gt;data have;
input value;
cards;
  371
  0
  145
   75
   40
   41
   19
    0
   10
    2
    0
    1
    3
    999
   0
   0
   0
   0
   0
   0
   0
   0
   0
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;What SAS code logic can&amp;nbsp;&amp;nbsp;remove last several zero value rows(In this example,remove all rows after value is 999)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my method please advise:&lt;/P&gt;
&lt;PRE&gt;data need1;
set have;
n=_n_;
run;
proc sort data=need1 out=need2;
by descending n;
run;
data need3;
retain flag 0;
set need2 nobs=obs;
do i=1 to obs;
if value=0 then do;
  if flag =0 then delete;
end;
else do;
  flag=1;
end;
end;
run;
proc sort data=need3 out=need(keep=value);
by n;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:29:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408093#M99523</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-10-27T16:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408094#M99524</link>
      <description>&lt;P&gt;What's the logic/rule?&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:17:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408094#M99524</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-27T16:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408095#M99525</link>
      <description>What is your criterion?  All trailing zeroes?  All zeroes after 999?  After the last 999?</description>
      <pubDate>Fri, 27 Oct 2017 16:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408095#M99525</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-27T16:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408096#M99526</link>
      <description>&lt;P&gt;There's really no way to do this in one step, since you have to keep reading in all the data to see if there is another nonzero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input value;&lt;BR /&gt;if value ne 0 then call symputx('good_obs', _n_);
cards;
  ...&lt;BR /&gt;;&lt;BR /&gt;data want;&lt;BR /&gt;set have (obs=&amp;amp;good_obs);&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408096#M99526</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-27T16:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408098#M99527</link>
      <description>&lt;P&gt;&lt;SPAN&gt;All trailing zeroes.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408098#M99527</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-10-27T16:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408099#M99528</link>
      <description>&lt;P&gt;Reverse your data, delete all the first zeros and then reverse it back.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408099#M99528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-27T16:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408103#M99530</link>
      <description>&lt;P&gt;This is good fancy solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also use SYMPUTX instead of symput takes the additional step of removing any leading blanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408103#M99530</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-10-27T16:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408107#M99531</link>
      <description>&lt;P&gt;You could use this technique; Seems to work with this case and it's one data step.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Merge dataset with itself, starting with subsequent values. This will get post values. Output if you don't have 2 trailing zeroes;
data want (drop = post_value1 post_value2);
merge have
      have (firstobs = 2 rename = value = post_value1)
      have (firstobs = 3 rename = value = post_value2);

if sum (value, post_value1, post_value2) &amp;gt; 0 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 16:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408107#M99531</guid>
      <dc:creator>Rwon</dc:creator>
      <dc:date>2017-10-27T16:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408116#M99533</link>
      <description>&lt;P&gt;MODIFY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input value @@;
   cards;
  371
  0
  145
   75    40
   41   19
    0   10
    2    0
    1    3
    999
   0   0
   0   0
   0   0
   0   0
   0
;
run;
proc print;
   run;
data have;
   do i=j by -1 to 1;
      modify have point=i nobs=j;
      if value eq 0 then remove;
      else stop;
      end;
   stop;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 17:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408116#M99533</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-10-27T17:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408137#M99539</link>
      <description>&lt;P&gt;Great solution! very fancy code!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I never used 'point=' &amp;nbsp;in a data step.I want to learn it by&amp;nbsp;this example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask what the "point=i" here does?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way here will be a problem if the have dataset created in a different environment than the update program:&lt;/P&gt;
&lt;P&gt;(that is if I created the 'have' &amp;nbsp;in UNIX, but when i use this code in PC to update the dataset, the error will happen.&lt;/P&gt;
&lt;P&gt;but that is fine, I can run the update code in UNIX too)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: File have cannot be updated because&lt;BR /&gt; its encoding does not match the session encoding or the&lt;BR /&gt; file is in a format native to another host, such as&lt;BR /&gt; HP_UX_64, RS_6000_AIX_64, SOLARIS_64, HP_IA64&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 19:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408137#M99539</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-10-27T19:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408141#M99543</link>
      <description>&lt;P&gt;POINT= is a MODIFY statement option to name the variable that points to the observation being modified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the documentation for complete details.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 19:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408141#M99543</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-10-27T19:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408149#M99547</link>
      <description>&lt;P&gt;I am not understand your code and the code has error after I run.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 19:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408149#M99547</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-10-27T19:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408179#M99564</link>
      <description>&lt;P&gt;I like the use of the MODIFY statement for removing observations in place (i.e. don't copy the original data set, just update in place).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However,&amp;nbsp;be aware that the data set attribute NOBS (number of observations) is unchanged by REMOVE statements.&amp;nbsp; I think this is because SAS needs to know how much physical space is used by the dataset.&amp;nbsp; And since it would be inefficient for SAS to delete internal records by overwriting all the subsequent records to new locations within the data set, they are just marked as removed, and total physical space is not reduced by&amp;nbsp;REMOVE.&amp;nbsp; However, the NLOBS (&lt;EM&gt;&lt;STRONG&gt;number of logical records&lt;/STRONG&gt;&lt;/EM&gt;) is adjusted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to make a new dataset, which will have NOBS=NLOBS, you can use this program, which uses the same "point=" logic as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  if _n_=1 then do p=nrecs to 1 by -1 until(value^=0);
    set have point=p nobs=nrecs;
  end;
  set have;
  if _n_&amp;gt;p then stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2017 21:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408179#M99564</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-27T21:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: remove last 0 rows(All trailing zeroes)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408332#M99640</link>
      <description>&lt;PRE&gt;
data have;
input value;
cards;
  371
  0
  145
   75
   40
   41
   19
    0
   10
    2
    0
    1
    3
    999
   0
   0
   0
   0
   0
   0
   0
   0
   0
;
run;
data have; 
 set have;
 if value=0 then group=0;
  else group=1;
run;
data have;
 set have end=last;
 by group notsorted;
 n+first.group;
 if last then call symputx('n',n);
run;
data want;
 set have;
 if n=&amp;amp;n and value=0 then delete;
 drop group n;
run;

&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Oct 2017 12:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/remove-last-0-rows-All-trailing-zeroes/m-p/408332#M99640</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-29T12:03:57Z</dc:date>
    </item>
  </channel>
</rss>

