<?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: count positive and neative values in a series in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264171#M7276</link>
    <description>&lt;P&gt;Last two suggestions worked perfectly, the first one did not work on the first attempt and I did not try again. Thanks much for all the suggestions, saved&amp;nbsp; me a lot of time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Apr 2016 14:00:37 GMT</pubDate>
    <dc:creator>cd2011</dc:creator>
    <dc:date>2016-04-15T14:00:37Z</dc:date>
    <item>
      <title>count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264021#M7272</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to do something like this, but stuck at this point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data shown below - I want to know how many negative values appear consistently. Ultimately I decide if several negative values appear consistently I want to keep them, otherwise leave. I dont use the positive values. I am able to get the counts of consequitive negative values, column "count". But I would like a column like "totct", which I am unable to calculate yet. As you can see there is no common id to do a group ct and them merge.&lt;/P&gt;
&lt;P&gt;Any help will be highly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Totct&lt;/P&gt;
&lt;TABLE width="340"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="148"&gt;3/1/2016 4:55&lt;/TD&gt;
&lt;TD width="64"&gt;-100&lt;/TD&gt;
&lt;TD width="64"&gt;1&lt;/TD&gt;
&lt;TD width="64"&gt;&lt;FONT color="#993366"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/1/2016 5:00&lt;/TD&gt;
&lt;TD&gt;-120&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#993366"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/1/2016 5:05&lt;/TD&gt;
&lt;TD&gt;-50&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#993366"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/1/2016 5:10&lt;/TD&gt;
&lt;TD&gt;-400&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#993366"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/1/2016 5:15&lt;/TD&gt;
&lt;TD&gt;-250&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#993366"&gt;5&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR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color="#993366"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3/1/2016 6:10&lt;/TD&gt;
&lt;TD&gt;-42&lt;/TD&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;&lt;FONT color="#993366"&gt;4&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a bunch.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 21:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264021#M7272</guid>
      <dc:creator>cd2011</dc:creator>
      <dc:date>2016-04-14T21:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264033#M7273</link>
      <description>&lt;P&gt;Here's a way that assumes your original data set is in sorted order BY DATE. &amp;nbsp;If that's not actually the case, we might have to revisit the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by descending date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;if count =0 then TotCnt=0;&lt;/P&gt;
&lt;P&gt;else TotCnt = max(TotCnt, Count);&lt;/P&gt;
&lt;P&gt;retain TotCnt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Optionally, put the data set back into its original order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=want;&lt;/P&gt;
&lt;P&gt;by date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264033#M7273</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-14T22:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264036#M7274</link>
      <description>&lt;P&gt;Another approach, first introduct a new variable 'sign' to mark the sign of the value, then 2X DOW get the job done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards truncover expandtabs;
	input date  anydtdtm13.  value;
	format date datetime25.2;
	sign=ifn(value &amp;lt; 0,-1,0);
	cards;
3/1/2016 4:55 -100 
3/1/2016 5:00 -120 
3/1/2016 5:05 -50 
3/1/2016 5:10 -400 
3/1/2016 5:15 -250 
3/1/2016 5:35 45  
3/1/2016 5:40 58  
3/1/2016 5:45 -80 
3/1/2016 5:50 4  
3/1/2016 5:55 -52.8
3/1/2016 6:00 -150 
3/1/2016 6:05 -400 
3/1/2016 6:10 -42 
;

data want;
	do totct=1 by 1 until (last.sign);
		set have;
		by sign notsorted;
	end;

	if sign &amp;gt; -1 then
		totct=0;

	do count=1 by 1 until (last.sign);
		set have;
		by sign notsorted;
		output;
	end;
run;
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Apr 2016 22:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264036#M7274</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-04-14T22:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264094#M7275</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile cards truncover expandtabs;
	input date  anydtdtm13.  value;
	format date datetime25.2;
	cards;
3/1/2016 4:55 -100 
3/1/2016 5:00 -120 
3/1/2016 5:05 -50 
3/1/2016 5:10 -400 
3/1/2016 5:15 -250 
3/1/2016 5:35 45  
3/1/2016 5:40 58  
3/1/2016 5:45 -80 
3/1/2016 5:50 4  
3/1/2016 5:55 -52.8
3/1/2016 6:00 -150 
3/1/2016 6:05 -400 
3/1/2016 6:10 -42 
;
run;
data temp;
 set have;
 if value lt 0 then count+1;
  else count=0;
 if count in (0 1) then group+1;
run;
data want;
 do until(last.group);
  set temp;
  by group;
 end;
 tot=count;
 do until(last.group);
  set temp;
  by group;
  output;
 end;
 drop group;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Apr 2016 07:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264094#M7275</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-04-15T07:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264171#M7276</link>
      <description>&lt;P&gt;Last two suggestions worked perfectly, the first one did not work on the first attempt and I did not try again. Thanks much for all the suggestions, saved&amp;nbsp; me a lot of time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 14:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264171#M7276</guid>
      <dc:creator>cd2011</dc:creator>
      <dc:date>2016-04-15T14:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: count positive and neative values in a series</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264194#M7277</link>
      <description>&lt;P&gt;Please select one of the working solutions and idicate it as your preferred solution. Other people using this forum will then be able to tell that your question was answered in a suitable fashion.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 15:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/count-positive-and-neative-values-in-a-series/m-p/264194#M7277</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-15T15:00:30Z</dc:date>
    </item>
  </channel>
</rss>

