<?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: incremental counting until variable is ne 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18572#M2812</link>
    <description>You could try something like this:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
	infile datalines delimiter = "" ;&lt;BR /&gt;
	input date anydtdte10. time 5.  turb ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
03/17/2008 1200 1&lt;BR /&gt;
03/17/2008 1215 1&lt;BR /&gt;
03/17/2008 1230 1&lt;BR /&gt;
03/17/2008 1245 0&lt;BR /&gt;
03/17/2008 1300 1&lt;BR /&gt;
03/17/2008 1315 1&lt;BR /&gt;
;&lt;BR /&gt;
DATA TEST1;&lt;BR /&gt;
	SET TEST;&lt;BR /&gt;
	RETAIN count;&lt;BR /&gt;
	if turb eq 1 then do;&lt;BR /&gt;
		count+1;&lt;BR /&gt;
		 	end;&lt;BR /&gt;
	if turb ne 1 then do;&lt;BR /&gt;
		count = 0;&lt;BR /&gt;
		end;&lt;BR /&gt;
Format date date9.;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 14 Apr 2009 22:30:18 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-04-14T22:30:18Z</dc:date>
    <item>
      <title>incremental counting until variable is ne 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18569#M2809</link>
      <description>I'd like to create a count variable that incrementally counts successive observations until my counted variable is not equal to 1, and then restarts counting when the variable is equal to 1 again.&lt;BR /&gt;
So here's my dataset:&lt;BR /&gt;
&lt;BR /&gt;
date time turb&lt;BR /&gt;
03/17/2008 1200 1&lt;BR /&gt;
03/17/2008 1215 1&lt;BR /&gt;
03/17/2008 1230 1&lt;BR /&gt;
03/17/2008 1245 0&lt;BR /&gt;
03/17/2008 1300 1&lt;BR /&gt;
03/17/2008 1315 1&lt;BR /&gt;
&lt;BR /&gt;
What I want is:&lt;BR /&gt;
date time turb count&lt;BR /&gt;
03/17/2008 1200 1 1&lt;BR /&gt;
03/17/2008 1215 1 2&lt;BR /&gt;
03/17/2008 1230 1 3&lt;BR /&gt;
03/17/2008 1245 0 0&lt;BR /&gt;
03/17/2008 1300 1 1&lt;BR /&gt;
03/17/2008 1315 1 2&lt;BR /&gt;
&lt;BR /&gt;
Any ideas for how to do this?&lt;BR /&gt;
kellyv</description>
      <pubDate>Tue, 14 Apr 2009 20:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18569#M2809</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-14T20:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counting until variable is ne 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18570#M2810</link>
      <description>Using a DATA step, a conditional assignment statement, illustrated as:&lt;BR /&gt;
&lt;BR /&gt;
IF &lt;CONDITION&gt; THEN &lt;ASSIGNMENT&gt;;&lt;BR /&gt;
&lt;BR /&gt;
Since you will be incrementing as mentioned, you can use SAS implicit RETAIN logic - have a look at the RETAIN statement for your counter variable.&lt;BR /&gt;
&lt;BR /&gt;
And when you reach the ".. is not equal t 1" condition, reset your counter variable to zero.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/ASSIGNMENT&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Tue, 14 Apr 2009 20:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18570#M2810</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-14T20:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counting until variable is ne 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18571#M2811</link>
      <description>From the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website, here is some SAS DATA Step programming documentation:&lt;BR /&gt;
&lt;BR /&gt;
Adding Information to a SAS Data Set&lt;BR /&gt;
&lt;BR /&gt;
Understanding the Assignment Statement &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001315210.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001315210.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Understanding DATA Step Processing&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304324.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304324.htm&lt;/A&gt;</description>
      <pubDate>Tue, 14 Apr 2009 21:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18571#M2811</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-04-14T21:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: incremental counting until variable is ne 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18572#M2812</link>
      <description>You could try something like this:&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
	infile datalines delimiter = "" ;&lt;BR /&gt;
	input date anydtdte10. time 5.  turb ;&lt;BR /&gt;
	datalines ;&lt;BR /&gt;
03/17/2008 1200 1&lt;BR /&gt;
03/17/2008 1215 1&lt;BR /&gt;
03/17/2008 1230 1&lt;BR /&gt;
03/17/2008 1245 0&lt;BR /&gt;
03/17/2008 1300 1&lt;BR /&gt;
03/17/2008 1315 1&lt;BR /&gt;
;&lt;BR /&gt;
DATA TEST1;&lt;BR /&gt;
	SET TEST;&lt;BR /&gt;
	RETAIN count;&lt;BR /&gt;
	if turb eq 1 then do;&lt;BR /&gt;
		count+1;&lt;BR /&gt;
		 	end;&lt;BR /&gt;
	if turb ne 1 then do;&lt;BR /&gt;
		count = 0;&lt;BR /&gt;
		end;&lt;BR /&gt;
Format date date9.;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 14 Apr 2009 22:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/incremental-counting-until-variable-is-ne-1/m-p/18572#M2812</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-14T22:30:18Z</dc:date>
    </item>
  </channel>
</rss>

