<?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 LOOP in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87129#M24886</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Karun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're doing a great job of reading through papers and picking up SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a couple of methods that I like to use when I'm trying to figure out code. Try it yourself, and see what you think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, from looking at the code, it looks like there's a dataset a that contains a variable Id that is some kind of "key", and a variable Var that is continuous, and it gets treated differently if it's missing. So I created the following SAS program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a(drop=I);&lt;BR /&gt; do i = 1 to 50;&lt;BR /&gt;&amp;nbsp; Id = floor(rand('uniform')*10);&lt;BR /&gt;&amp;nbsp; Var = rand('uniform') * 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if rand('uniform') &amp;lt; .1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; call missing(Var);&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt; by Id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should be familiar with most of it. In terms of the unusual bits, the do...end will loop 50 times, and the output before the end writes a record, so it'll write 50 records to SAS dataset a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The rand('uniform') function will generate a random number uniformly distributed between 0 and 1. Multiplying it by 10 will uniformly distribute it between 0 and 10 (actually 9.9...), and the floor function will remove the decimal places, so Id will be a random integer between 0 and 9.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Same idea for Var, but we'll make it between 0 and 100, and we won't remove the decimal places.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The if statement will set Var to missing 10% of the time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And because there's a "by" statement in the code to be examined, we need to sort our data by the variable in the "by" statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the code under examination, with the changes I made:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data B ( Keep = Id Prod Sum Count Mean) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; putlog 'After Data statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Prod = 1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Do Count = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; putlog 'After Do statement ' _all_;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'After Set statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Missing (Var) Then Continue ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mcount = Sum (Mcount, 1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prod = Prod * Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum = Sum (Sum, Var) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'Before End statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mean = Sum / Mcount ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'Before Run statement ' _all_;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing I did was to add five "putlog" statements in. These will print out the comment of where in the code we are, and then the _all_ clause prints out the values of all of the variables in the program. As a result, you get a log listing that pretty much lets you track the logic of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Play with it, and see what you think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Oct 2012 16:32:52 GMT</pubDate>
    <dc:creator>TomKari</dc:creator>
    <dc:date>2012-10-07T16:32:52Z</dc:date>
    <item>
      <title>DOW LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87127#M24884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi TEam,&lt;/P&gt;&lt;P&gt;I was reading a paper on Dow Loops.&lt;/P&gt;&lt;P&gt;&lt;A href="http://analytics.ncsu.edu/sesug/2010/BB13.Dorfman.pdf" target="_blank" title="http://analytics.ncsu.edu/sesug/2010/BB13.Dorfman.pdf"&gt;http://analytics.ncsu.edu/sesug/2010/BB13.Dorfman.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The example is from page 2 of this paper.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"If VAR is missing CONTINUE passes the control straight to the bottom of the loop".&lt;/P&gt;&lt;P&gt;What is the meaning of bottom of the loop? Is it not gona calculate &lt;STRONG&gt;Mcount&lt;/STRONG&gt; &lt;STRONG&gt;Prod&lt;/STRONG&gt; and &lt;STRONG&gt;SUm for that variable and goes to the next variable but still with in the loop&lt;/STRONG&gt;?Is that the meaning ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Secondly,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;"PROD and COUNT are&lt;/P&gt;&lt;P&gt;set to 1, and the non-retained SUM, MEAN, and MCOUNT are set to missing by the default action of the&lt;/P&gt;&lt;P&gt;implied loop (program control at the top of the implied loop)."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This sentence says that SUM Mean and Count are set to missing . But what lines in the code sets these values to missing??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated possibly with an example would be great&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data B ( Keep = Id Prod Sum Count Mean) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Prod = 1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Do Count = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Missing (Var) Then Continue ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mcount = Sum (Mcount, 1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prod = Prod * Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum = Sum (Sum, Var) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mean = Sum / Mcount ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Karun Diri&#xD;
&#xD;
Also I feel the keep statement would have been good with the set statement rather than the Data B&#xD;
Any suggestions??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2012 16:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87127#M24884</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2012-10-05T16:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: DOW LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87128#M24885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The CONTINUE transfers control to the bottom of the loop.&amp;nbsp; This is the END statement, consequently the three assignment statements are not executed when VAR is missing.&amp;nbsp; Note that since you are using a DOW loop, the DATA statement will only be executed once for each unique ID.&lt;/P&gt;&lt;P&gt;2) During the execution phase, non-retained variables are set to missing, when the DATA statement is executed.&amp;nbsp; In this case these will be any variables that are not on the incoming data set (A).&lt;/P&gt;&lt;P&gt;3) the KEEP= data set option will be applied to the data set it is associated with.&amp;nbsp; To control incoming variables use it on the data set on the SET statement.&amp;nbsp; When used with the data set(s) on the DATA statement, the KEEP= applies to the new data set.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 06:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87128#M24885</guid>
      <dc:creator>ArtC</dc:creator>
      <dc:date>2012-10-07T06:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: DOW LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87129#M24886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Karun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're doing a great job of reading through papers and picking up SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a couple of methods that I like to use when I'm trying to figure out code. Try it yourself, and see what you think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, from looking at the code, it looks like there's a dataset a that contains a variable Id that is some kind of "key", and a variable Var that is continuous, and it gets treated differently if it's missing. So I created the following SAS program:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a(drop=I);&lt;BR /&gt; do i = 1 to 50;&lt;BR /&gt;&amp;nbsp; Id = floor(rand('uniform')*10);&lt;BR /&gt;&amp;nbsp; Var = rand('uniform') * 100;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if rand('uniform') &amp;lt; .1 then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; call missing(Var);&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort;&lt;BR /&gt; by Id;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should be familiar with most of it. In terms of the unusual bits, the do...end will loop 50 times, and the output before the end writes a record, so it'll write 50 records to SAS dataset a;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The rand('uniform') function will generate a random number uniformly distributed between 0 and 1. Multiplying it by 10 will uniformly distribute it between 0 and 10 (actually 9.9...), and the floor function will remove the decimal places, so Id will be a random integer between 0 and 9.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Same idea for Var, but we'll make it between 0 and 100, and we won't remove the decimal places.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The if statement will set Var to missing 10% of the time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And because there's a "by" statement in the code to be examined, we need to sort our data by the variable in the "by" statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the code under examination, with the changes I made:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data B ( Keep = Id Prod Sum Count Mean) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; putlog 'After Data statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Prod = 1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Do Count = 1 By 1 Until ( Last.Id ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; putlog 'After Do statement ' _all_;&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'After Set statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If Missing (Var) Then Continue ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mcount = Sum (Mcount, 1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prod = Prod * Var ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum = Sum (Sum, Var) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'Before End statement ' _all_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mean = Sum / Mcount ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; putlog 'Before Run statement ' _all_;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing I did was to add five "putlog" statements in. These will print out the comment of where in the code we are, and then the _all_ clause prints out the values of all of the variables in the program. As a result, you get a log listing that pretty much lets you track the logic of the program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Play with it, and see what you think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Oct 2012 16:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DOW-LOOP/m-p/87129#M24886</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2012-10-07T16:32:52Z</dc:date>
    </item>
  </channel>
</rss>

