<?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: DOW: do until(last.var) and do _n_=1 by 1 until (last.var)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145056#M261920</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An easy way to see what is going on in the pdv is to carefully place 'put _all_;' statements at strategic places in your code.&amp;nbsp; E.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id var;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Do _n_ = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'before set 1st Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; By Id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum = Sum (Sum, Var) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'after set 1st Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Mean = Sum / _n_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Do _n_ = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'before set 2nd Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; By Id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'after set 2nd Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you can increment _n_ by whatever value you want but, since you would likely be including the index for use as a counter, you would typically only increment by 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the benefits of using _n_, rather than some other variable, is that you don't have to drop it from your output, as _n_ is never included in the output dataset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Dec 2014 22:57:37 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2014-12-10T22:57:37Z</dc:date>
    <item>
      <title>DOW: do until(last.var) and do _n_=1 by 1 until (last.var)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145055#M261919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SAS experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens when we use set statement inside a do loop in PDV? and is do until(last.var) and do _n_=1 by 1 until (last.var) different from each other? _n_ as an index variable- so does that mean _n_ can be incremented to 2&amp;nbsp; and beyond during the processing of the first observation of a SAS dataset? Please let me know the significance of using _n_ as index variable or is it possible to use some other index variable instead of _n_ for a similar example/instance?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have read the long papers on DOW but still haven't grasped the essential processing. I'd appreciate if anybody can explain with simpler example than the illustration in SUGI papers?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much in advance if you lend me your valuable time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;God bless&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Dec 2014 19:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145055#M261919</guid>
      <dc:creator>Allaluiah</dc:creator>
      <dc:date>2014-12-10T19:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: DOW: do until(last.var) and do _n_=1 by 1 until (last.var)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145056#M261920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An easy way to see what is going on in the pdv is to carefully place 'put _all_;' statements at strategic places in your code.&amp;nbsp; E.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input id var;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;1 3&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 2&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 4&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data b;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Do _n_ = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'before set 1st Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; By Id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum = Sum (Sum, Var) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'after set 1st Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Mean = Sum / _n_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Do _n_ = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'before set 2nd Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; By Id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; put 'after set 2nd Iteration:'_all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you can increment _n_ by whatever value you want but, since you would likely be including the index for use as a counter, you would typically only increment by 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the benefits of using _n_, rather than some other variable, is that you don't have to drop it from your output, as _n_ is never included in the output dataset.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Dec 2014 22:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145056#M261920</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-12-10T22:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: DOW: do until(last.var) and do _n_=1 by 1 until (last.var)?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145057#M261921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ad ".. simpler example than the illustration in SUGI papers ..". Maybe these little programs are good to start with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The difference between "Do I=1 By 1 Until (Last.Var)" and "Do Until (Last.Var)" is that you get a counter "I" which can be useful, for example to calculate a mean (see code 4).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data A;&lt;BR /&gt;&amp;nbsp; Input N $ X Y;&lt;BR /&gt;&amp;nbsp; Datalines;&lt;BR /&gt;A 378 334&lt;BR /&gt;A 362 .&lt;BR /&gt;A 221 93&lt;BR /&gt;B 210 12&lt;BR /&gt;B 100 .&lt;BR /&gt;B 389 28&lt;BR /&gt;B 723 92&lt;BR /&gt;C 23 . &lt;BR /&gt;C 98 .&lt;BR /&gt;C 12 239&lt;BR /&gt;;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;* code 1: Fill out missing Y's with predecessor - NO by-processing;&lt;BR /&gt;Data Y_Complete (Drop=dummy);&lt;BR /&gt;&amp;nbsp; Do Until (Eof);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A End=Eof;&lt;BR /&gt; If not Missing (Y) Then dummy=Y;&lt;BR /&gt; Else If Missing (Y) Then Y=dummy;&lt;BR /&gt; Output;&lt;BR /&gt;&amp;nbsp; End;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;* Code 2: Calculate Sum and Mean of all X's;&lt;BR /&gt;Data Calculate_Total_Mean (Keep=Mean_X Total_X);&lt;BR /&gt;&amp;nbsp; Do _N_=1 By 1 Until (Eof); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A End=Eof;&lt;BR /&gt; Total_X=Sum(X,Total_X);&lt;BR /&gt;&amp;nbsp; End; &lt;BR /&gt;&amp;nbsp; Mean_X=Total_X/_N_;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;* code 3: Mean values by group;&lt;BR /&gt;Data Instead_of_proc_means (Keep=N Mean_X);&lt;BR /&gt;&amp;nbsp; Do i=1 By 1 Until (Last.N);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A;&lt;BR /&gt; By N;&lt;BR /&gt; Total=Sum(X,Total);&lt;BR /&gt;&amp;nbsp; End;&lt;BR /&gt;&amp;nbsp; Mean_X=Total/i;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;* code 4: Mean values by group, keep all observations;&lt;BR /&gt;Data Add_Mean_to_All_Xes;&lt;BR /&gt;&amp;nbsp; Do _N_=1 By 1 Until (Last.N); * "_N_=1 By 1" .. you need a counter to calculate the mean;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A;&lt;BR /&gt; By N;&lt;BR /&gt; Total=Sum(X,Total);&lt;BR /&gt;&amp;nbsp; End;&lt;BR /&gt;&amp;nbsp; Mean_X=Total/_N_; &lt;BR /&gt;&amp;nbsp; Do Until (Last.N); * you only want to loop and output the data lines;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set A;&lt;BR /&gt; By N;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output;&lt;BR /&gt;&amp;nbsp; End;&lt;BR /&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Dec 2014 09:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DOW-do-until-last-var-and-do-n-1-by-1-until-last-var/m-p/145057#M261921</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-12-11T09:35:29Z</dc:date>
    </item>
  </channel>
</rss>

