<?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 Help with adding value up when condition meet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497216#M131707</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Everyone,&lt;BR /&gt;I have a data as below (with many numeric variables) and at the end, I only want to pick record with CHECK^=.&lt;BR /&gt;for that record, for each numeric variable (v1, v2.....), I want to add all values&amp;nbsp;from after the last time Check^=.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;so row 1 will be kept&lt;/P&gt;
&lt;P&gt;row 4 will be kept and the Check, V1, V2 as below:&lt;BR /&gt;5&amp;nbsp;(2+1) (3)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;last row will be&amp;nbsp;&lt;SPAN&gt;kept and the Check, V1, V2 as below:&lt;/SPAN&gt;&lt;BR /&gt;9&amp;nbsp;1 (2+1)&lt;/P&gt;
&lt;P&gt;Can you please help me with that?&lt;/P&gt;
&lt;P&gt;Thank you so much&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;set&amp;nbsp; &amp;nbsp; &amp;nbsp;check&amp;nbsp; &amp;nbsp; v1 v2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3 4&lt;BR /&gt;. 2 .&lt;BR /&gt;. 1 3&lt;BR /&gt;&lt;STRONG&gt;5&amp;nbsp;. .&lt;/STRONG&gt;&lt;BR /&gt;. 1 2&lt;BR /&gt;&lt;STRONG&gt;9&amp;nbsp;. 1&lt;/STRONG&gt;&lt;BR /&gt;;run;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 02:53:45 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2018-09-20T02:53:45Z</dc:date>
    <item>
      <title>Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497216#M131707</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Everyone,&lt;BR /&gt;I have a data as below (with many numeric variables) and at the end, I only want to pick record with CHECK^=.&lt;BR /&gt;for that record, for each numeric variable (v1, v2.....), I want to add all values&amp;nbsp;from after the last time Check^=.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;so row 1 will be kept&lt;/P&gt;
&lt;P&gt;row 4 will be kept and the Check, V1, V2 as below:&lt;BR /&gt;5&amp;nbsp;(2+1) (3)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;last row will be&amp;nbsp;&lt;SPAN&gt;kept and the Check, V1, V2 as below:&lt;/SPAN&gt;&lt;BR /&gt;9&amp;nbsp;1 (2+1)&lt;/P&gt;
&lt;P&gt;Can you please help me with that?&lt;/P&gt;
&lt;P&gt;Thank you so much&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;set&amp;nbsp; &amp;nbsp; &amp;nbsp;check&amp;nbsp; &amp;nbsp; v1 v2;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3 4&lt;BR /&gt;. 2 .&lt;BR /&gt;. 1 3&lt;BR /&gt;&lt;STRONG&gt;5&amp;nbsp;. .&lt;/STRONG&gt;&lt;BR /&gt;. 1 2&lt;BR /&gt;&lt;STRONG&gt;9&amp;nbsp;. 1&lt;/STRONG&gt;&lt;BR /&gt;;run;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497216#M131707</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-09-20T02:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497217#M131708</link>
      <description>&lt;P&gt;I see you have over 500 posts to sas communities.&amp;nbsp; Could you please provide the sample data with working data step code?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497217#M131708</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-20T02:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497219#M131710</link>
      <description>&lt;P&gt;I totally stuck with that problem.&lt;/P&gt;
&lt;P&gt;I am not sure what info you need since I have the sample data at the end. Also the output data is explained in the body.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497219#M131710</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-09-20T02:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497222#M131711</link>
      <description>&lt;P&gt;I requested a working DATA HAVE code, simply as a good model for others posting questions.&amp;nbsp; In your case, simply using INPUT instead of SET.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand you only want to output the records with check^=., and V1 and V2 modified as described:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input     check    v1 v2;
datalines;
1 3 4
. 2 .
. 1 3
5 . .
. 1 2
9 . 1
run;

data want (drop=_:);
  set have;
  _v1+v1;
  _v2+v2;
  if check^=.;
  v1=_v1;
  v2=_v2;
  call missing(of _:);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want ALL records, then change "if check^=.;" with "if check ^=. then do;", and put an "end;" statement after the call missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497222#M131711</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-20T02:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497224#M131712</link>
      <description>&lt;P&gt;Thanks a lot for your help.&lt;/P&gt;
&lt;P&gt;That works perfectly.&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 02:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497224#M131712</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-09-20T02:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497227#M131714</link>
      <description>&lt;P&gt;By the way, is there any way to do that for all _numeric_ variables since I have 20+ variables to perform that process?&lt;/P&gt;
&lt;P&gt;And when I change my file, the variables are not the same.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 03:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497227#M131714</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-09-20T03:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497496#M131876</link>
      <description>&lt;P&gt;Yes, you can do this for all numeric variables, but instead of summing statements, like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _v1+v1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; _v2+v2;&lt;/P&gt;
&lt;P&gt;you can use a temporary array.&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     check    v1 v2;
datalines;
1 3 4
. 2 .
. 1 3
5 . .
. 1 2
9 . 1
run;

data want (drop=_:);
  set have;
  array tmps {30} _temporary_;
  array nbrs {*} _numeric_;
  do _i=1 to dim(nbrs);
    tmps{_i}+nbrs{_i};
  end;
  if check^=.;
  do _i=1 to dim(nbrs);
    nbrs{_i}=tmps{_i};
    tmps{_i}=.;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only caveat is to declare the array tmps to have at least as many elements (I used 30 above) as the array nbrs.&amp;nbsp; It can be larger, but not smaller.&amp;nbsp; You could declare _tmps to be of size 1,000 and it wouldn't hurt.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 17:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497496#M131876</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-20T17:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help with adding value up when condition meet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497550#M131896</link>
      <description>&lt;P&gt;Thank you so much for your code.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 20:40:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-adding-value-up-when-condition-meet/m-p/497550#M131896</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2018-09-20T20:40:41Z</dc:date>
    </item>
  </channel>
</rss>

