<?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: Iterating a step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287705#M59563</link>
    <description>&lt;P&gt;I have uploaded a larger data set that will help with my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I have data for Variable1 that is measured every second. The actual data comes from a belt weigher. This belt weigher feed a truck, column 'new'. I am looking to obtain data that sums Variable1 for each truck. Ideally I want a dataset that gives me tonnes/truck over each day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help in advance.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2016 02:27:05 GMT</pubDate>
    <dc:creator>John3</dc:creator>
    <dc:date>2016-07-28T02:27:05Z</dc:date>
    <item>
      <title>Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286031#M59455</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Variable 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Variable 2&lt;/P&gt;&lt;P&gt;01JUN16:14:50:28 0.0407787557 &amp;nbsp;.&amp;nbsp;&lt;BR /&gt;01JUN16:14:50:29 0.0330219989 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:30 0.0366766247 &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01JUN16:14:50:30 &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;75&lt;BR /&gt;01JUN16:14:50:31 0.0366766247 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:32 0.0330219989 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:33 0.0354086933 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:33 . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76&lt;BR /&gt;01JUN16:14:50:34 0.0393616559 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:35 0.0308341957 &amp;nbsp;.&lt;BR /&gt;01JUN16:14:50:36 0.0393616559 &amp;nbsp;.&lt;/P&gt;&lt;P&gt;I am hoping to get a columun that continues the Variable 2 value until it gets to the next number where it will then carry on this number. Ie this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Variable 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Variable 2 Solution&lt;/P&gt;&lt;P&gt;01JUN16:14:50:28 0.0407787557 &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74&lt;BR /&gt;01JUN16:14:50:29 0.0330219989 &lt;SPAN&gt;&amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:30 0.0366766247 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;74&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01JUN16:14:50:30 &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;75 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&lt;BR /&gt;01JUN16:14:50:31 0.0366766247 &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&lt;BR /&gt;01JUN16:14:50:32 0.0330219989 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:33 0.0354086933 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;75&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:33 . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;76 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;76&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:34 0.0393616559 &lt;SPAN&gt;&amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:35 0.0308341957 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76&lt;/SPAN&gt;&lt;BR /&gt;01JUN16:14:50:36 0.0393616559 &amp;nbsp;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 03:07:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286031#M59455</guid>
      <dc:creator>John3</dc:creator>
      <dc:date>2016-07-21T03:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286038#M59456</link>
      <description>&lt;P&gt;Look at the RETAIN statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Retain solution;&lt;/P&gt;
&lt;P&gt;if _n_=1 then solution = 74;&lt;/P&gt;
&lt;P&gt;if variable2 ne . Then solution=variable2;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 04:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286038#M59456</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-21T04:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286045#M59457</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover expandtabs;
input Time : $40.    Variable1        Variable2;
cards;
01JUN16:14:50:28 0.0407787557  . 
01JUN16:14:50:29 0.0330219989  .
01JUN16:14:50:30 0.0366766247  
01JUN16:14:50:30  .                    75
01JUN16:14:50:31 0.0366766247  .
01JUN16:14:50:32 0.0330219989  .
01JUN16:14:50:33 0.0354086933  .
01JUN16:14:50:33 .                     76
01JUN16:14:50:34 0.0393616559  .
01JUN16:14:50:35 0.0308341957  .
01JUN16:14:50:36 0.0393616559  .
;
run;

data want;
retain temp;
 do until(not missing(Variable2) or last1);
  set have end=last1;
 end;

 if not missing(Variable2) then temp=Variable2;
  else flag=1;
 
 do until(not missing(Variable2) or last2);
  set have end=last2;
  new=coalesce(Variable2,temp-1);
  if flag then new=temp;
   else new=coalesce(Variable2,temp-1);
  output;
 end;
drop temp flag Variable2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2016 05:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/286045#M59457</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-21T05:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287698#M59561</link>
      <description>&lt;P&gt;Thanks for that solution. It works perfectly except my data set goes back to 1&amp;nbsp;after each day (Variable2). The data below shows how the last &amp;nbsp;number in the Variable2 column doesn't get retained but goes to 0.&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; Date_Time &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Variable1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;SPAN&gt;Variable2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;20JUL2016 20JUL16:00:19:26 0.0509201597 124&lt;BR /&gt;20JUL2016 20JUL16:00:19:27 0.054355847 124&lt;BR /&gt;20JUL2016 20JUL16:00:19:28 0.051141817 124&lt;BR /&gt;20JUL2016 20JUL16:00:19:29 0.0469164758 124&lt;BR /&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20JUL16:00:19:29 . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;125&lt;BR /&gt;20JUL2016 20JUL16:00:19:30 0.0441457602 0&lt;BR /&gt;20JUL2016 20JUL16:00:19:31 0.0492992911 0&lt;BR /&gt;20JUL2016 20JUL16:00:19:32 0.0641364728 0&lt;BR /&gt;20JUL2016 20JUL16:00:19:33 0.0691930286 0&lt;BR /&gt;20JUL2016 20JUL16:00:19:34 0.0612133679 0&lt;BR /&gt;20JUL2016 20JUL16:00:19:35 0.0720607192 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how to fix this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition, do you have any code that will sum Variable1 for each Variable2 and Date.&lt;/P&gt;&lt;P&gt;Ie&lt;/P&gt;&lt;P&gt;20Jul2016 1 10.5&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20Jul2016 2 11&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;20Jul2016 3 &amp;nbsp;7&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;.....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;21Jul2016 1 &amp;nbsp;8.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;etc&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 01:33:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287698#M59561</guid>
      <dc:creator>John3</dc:creator>
      <dc:date>2016-07-28T01:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287704#M59562</link>
      <description>&lt;PRE&gt;
Your data does not look like what you showed before, there are not any missing value . 

data have;
infile cards truncover expandtabs;
input Date : $20.   Date_Time  : $40.    Variable1        Variable2;
cards;
0JUL2016 20JUL16:00:19:26   0.0509201597 124
20JUL2016 20JUL16:00:19:27   0.054355847 124
20JUL2016 20JUL16:00:19:28   0.051141817 124
20JUL2016 20JUL16:00:19:29   0.0469164758 124
.         20JUL16:00:19:29    .            125
20JUL2016 20JUL16:00:19:30   0.0441457602 .
20JUL2016 20JUL16:00:19:31   0.0492992911 .
20JUL2016 20JUL16:00:19:32   0.0641364728 .
20JUL2016 20JUL16:00:19:33   0.0691930286 .
20JUL2016 20JUL16:00:19:34   0.0612133679 .
20JUL2016 20JUL16:00:19:35   0.0720607192 .
;
run;

data want;
retain temp;
 do until(not missing(Variable2) or last1);
  set have end=last1;
 end;

 if not missing(Variable2) then temp=Variable2;
  else flag=1;
 
 do until(not missing(Variable2) or last2);
  set have end=last2;
  if flag then new=temp;
   else new=coalesce(Variable2,temp-1);
  output;
 end;
drop temp flag Variable2;
run;





OUTPUT:
Before
Date	Date_Time	Variable1	Variable2
0JUL2016	20JUL16:00:19:26	0.050920	124
20JUL2016	20JUL16:00:19:27	0.054356	124
20JUL2016	20JUL16:00:19:28	0.051142	124
20JUL2016	20JUL16:00:19:29	0.046916	124
 	20JUL16:00:19:29	.	125
20JUL2016	20JUL16:00:19:30	0.044146	.
20JUL2016	20JUL16:00:19:31	0.049299	.
20JUL2016	20JUL16:00:19:32	0.064136	.
20JUL2016	20JUL16:00:19:33	0.069193	.
20JUL2016	20JUL16:00:19:34	0.061213	.
20JUL2016	20JUL16:00:19:35	0.072061	.
After
Date	Date_Time	Variable1	new
0JUL2016	20JUL16:00:19:26	0.050920	124
20JUL2016	20JUL16:00:19:27	0.054356	124
20JUL2016	20JUL16:00:19:28	0.051142	124
20JUL2016	20JUL16:00:19:29	0.046916	124
 	20JUL16:00:19:29	.	125
20JUL2016	20JUL16:00:19:30	0.044146	125
20JUL2016	20JUL16:00:19:31	0.049299	125
20JUL2016	20JUL16:00:19:32	0.064136	125
20JUL2016	20JUL16:00:19:33	0.069193	125
20JUL2016	20JUL16:00:19:34	0.061213	125
20JUL2016	20JUL16:00:19:35	0.072061	125





In addition, do you have any code that will sum Variable1 for each Variable2 and Date.
Ie
20Jul2016 1 10.5
20Jul2016 2 11
20Jul2016 3  7
.....
21Jul2016 1  8.5

I don't understand what you mean. Where is 1,2,3,..10.5,11,7..   coming from ?

&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 02:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287704#M59562</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-28T02:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287705#M59563</link>
      <description>&lt;P&gt;I have uploaded a larger data set that will help with my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I have data for Variable1 that is measured every second. The actual data comes from a belt weigher. This belt weigher feed a truck, column 'new'. I am looking to obtain data that sums Variable1 for each truck. Ideally I want a dataset that gives me tonnes/truck over each day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 02:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287705#M59563</guid>
      <dc:creator>John3</dc:creator>
      <dc:date>2016-07-28T02:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287715#M59564</link>
      <description>&lt;PRE&gt;
Sorry. Still can't get your point . Maybe you need this :



data have;
infile cards truncover expandtabs;
input Date : $20.   Date_Time  : $40.    Variable1        Variable2;
cards;
0JUL2016 20JUL16:00:19:26   0.0509201597 124
20JUL2016 20JUL16:00:19:27   0.054355847 124
20JUL2016 20JUL16:00:19:28   0.051141817 124
20JUL2016 20JUL16:00:19:29   0.0469164758 124
.         20JUL16:00:19:29    .            125
20JUL2016 20JUL16:00:19:30   0.0441457602 .
20JUL2016 20JUL16:00:19:31   0.0492992911 .
20JUL2016 20JUL16:00:19:32   0.0641364728 .
20JUL2016 20JUL16:00:19:33   0.0691930286 .
20JUL2016 20JUL16:00:19:34   0.0612133679 .
20JUL2016 20JUL16:00:19:35   0.0720607192 .
;
run;

data want;
retain temp;
 do until(not missing(Variable2) or last1);
  set have end=last1;
 end;

 if not missing(Variable2) then temp=Variable2;
  else flag=1;
 
 do until(not missing(Variable2) or last2);
  set have end=last2;
  if flag then new=temp;
   else new=coalesce(Variable2,temp-1);
  output;
 end;
drop temp flag ;
run;

proc means data=want noprint;
 by Date new notsorted;
 var Variable1;
 output out=final_want sum=sum_Variable1;
run;


&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 03:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287715#M59564</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-28T03:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating a step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287716#M59565</link>
      <description>&lt;P&gt;That worked exactly! Thankyou very much&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 03:45:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Iterating-a-step/m-p/287716#M59565</guid>
      <dc:creator>John3</dc:creator>
      <dc:date>2016-07-28T03:45:56Z</dc:date>
    </item>
  </channel>
</rss>

