<?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: do loop value assignment not working in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39021#M7903</link>
    <description>Start a new thread for each post / question -- there are others on this forum besides myself who can assist.  &lt;BR /&gt;
&lt;BR /&gt;
However, for me personally -- in about 20 minutes you will be competing with my Sunday afternoon cocktail session, and...DANG!....I still need to get the recycle and house-trash picked up before commencing iterative libation consumption exercises.&lt;BR /&gt;
&lt;BR /&gt;
Again, there are others monitoring these forums and I'd encourage you to use them, wisely of course, after doing your own leg-work first, regardless of the specific concern.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Sun, 31 May 2009 19:36:47 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-05-31T19:36:47Z</dc:date>
    <item>
      <title>do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39012#M7894</link>
      <description>I have the following data structure:&lt;BR /&gt;
&lt;BR /&gt;
value      var_name       varnum       valnum&lt;BR /&gt;
horse      animal               1                1&lt;BR /&gt;
cat          animal               1               2&lt;BR /&gt;
dog         animal               1               3&lt;BR /&gt;
high        priority               2                1&lt;BR /&gt;
low         priority               2                2 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I have coded the following:&lt;BR /&gt;
&lt;BR /&gt;
%let neqtn=3;&lt;BR /&gt;
&lt;BR /&gt;
data all_map;&lt;BR /&gt;
do _n_=1 until (last.valnum);&lt;BR /&gt;
betaval=1;&lt;BR /&gt;
set total ;&lt;BR /&gt;
by varnum valnum;&lt;BR /&gt;
 if last.varnum ne 1 then do;&lt;BR /&gt;
 betaval=betaval +(&amp;amp;neqtn-1);&lt;BR /&gt;
 retain betaval;&lt;BR /&gt;
 end;&lt;BR /&gt;
 else do;&lt;BR /&gt;
 betaval=0;&lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This produces the following result:&lt;BR /&gt;
&lt;BR /&gt;
value      var_name       varnum       valnum  betaval&lt;BR /&gt;
horse      animal               1                1        3&lt;BR /&gt;
cat          animal               1               2         3&lt;BR /&gt;
dog         animal               1               3         0&lt;BR /&gt;
high        priority               2                1         2&lt;BR /&gt;
low         priority               2                2         0&lt;BR /&gt;
&lt;BR /&gt;
This is what I want it to produce:&lt;BR /&gt;
&lt;BR /&gt;
value      var_name       varnum       valnum   betaval&lt;BR /&gt;
horse      animal               1                1                 B3&lt;BR /&gt;
cat          animal               1               2                 B5&lt;BR /&gt;
dog         animal               1               3                    -sum(B3+B5)&lt;BR /&gt;
high        priority               2                1                B7&lt;BR /&gt;
low         priority               2                2                  -B7&lt;BR /&gt;
&lt;BR /&gt;
etc. I am assigning the reference to the beta value not the actual value at this point so the beta value for the last obs of a variable will still only be a reference to multiple beta values(from previous observations). Also, they are incremented by a known value, neqtn-1( number of equations -1), in this case 2. How do I retain the betaval across variable groups to allow incrementing to correct beta? It resets for each new variable. How do I assign betaval to last obs in a group appropriately(my current code sets last obs beta val=0, short of a solution)?</description>
      <pubDate>Fri, 29 May 2009 20:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39012#M7894</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-29T20:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39013#M7895</link>
      <description>To start, you are using a SAS-reserved variable _N_ which is controlled by the SET statement.  Suggest you might add some additional diagnostic statements for your own debugging opportunity, such as:&lt;BR /&gt;
&lt;BR /&gt;
PUTLOG '&amp;gt;DIAG00' /_ALL_;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 29 May 2009 21:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39013#M7895</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-29T21:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39014#M7896</link>
      <description>Thanks for the tip. The diagnostics are helpful. I know the code cannot accomplish what I need as written however. Any suggestions for best way to initialize betaval or to retain values for last obs.&lt;BR /&gt;
&lt;BR /&gt;
Thanks.</description>
      <pubDate>Fri, 29 May 2009 21:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39014#M7896</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-29T21:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39015#M7897</link>
      <description>Investigate the LAG function.  There is also a RETAIN statement along with an assignment to allow a variable value to be captured for a subsequent DATA step pass.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 29 May 2009 21:53:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39015#M7897</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-29T21:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39016#M7898</link>
      <description>Thanks Scott, I'll look into those and see if they're able to achieve what I need. &lt;BR /&gt;
&lt;BR /&gt;
Any other suggestions are appreciated.</description>
      <pubDate>Fri, 29 May 2009 21:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39016#M7898</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-29T21:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39017#M7899</link>
      <description>You may need to generating a separate file with desired values and merge that file back against your source file.  Otherwise I don't see how you can decide conditionally when/how to capture and retain values, since you need them for each pertinent observation.  A pre-processing SORT and DATA step, followed by another SORT and MERGE sounds more appropriate.  Scrap the idea of using LAG or RETAIN, as well.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 29 May 2009 22:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39017#M7899</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-29T22:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39018#M7900</link>
      <description>Change the statement betaval=1; to if _n_=1 then betval=1; &lt;BR /&gt;
&lt;BR /&gt;
~ Sukanya E</description>
      <pubDate>Fri, 29 May 2009 22:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39018#M7900</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-29T22:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39019#M7901</link>
      <description>Thanks Scott.  I think you're right. I was able to correct the assignment of betaval  for observations  1&lt;X&gt;&lt;N. for="" the="" nth="" observation="" assignment="" i="" agree="" it="" will="" have="" to="" be="" accomplished="" in="" a="" separate="" step="" after="" first="" writing="" out="" the="" betavals="" for="" n="1" thru=""&gt;&lt;/N.&gt;&lt;/X&gt;</description>
      <pubDate>Sun, 31 May 2009 18:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39019#M7901</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-31T18:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39020#M7902</link>
      <description>Scott I have a couple of more issues needing resolution to get the larger program to perform properly and meet a tight deadline -are you available this afternoon for some questions. They are macro and array related. - sry for posting request directly to thread - I'm not aware of another method.</description>
      <pubDate>Sun, 31 May 2009 18:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39020#M7902</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-31T18:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39021#M7903</link>
      <description>Start a new thread for each post / question -- there are others on this forum besides myself who can assist.  &lt;BR /&gt;
&lt;BR /&gt;
However, for me personally -- in about 20 minutes you will be competing with my Sunday afternoon cocktail session, and...DANG!....I still need to get the recycle and house-trash picked up before commencing iterative libation consumption exercises.&lt;BR /&gt;
&lt;BR /&gt;
Again, there are others monitoring these forums and I'd encourage you to use them, wisely of course, after doing your own leg-work first, regardless of the specific concern.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 31 May 2009 19:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39021#M7903</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-31T19:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: do loop value assignment not working</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39022#M7904</link>
      <description>Thanks for responding to my post! I will start a thread for each issue. Hope you enjoyed your afternoon happy hour.&lt;BR /&gt;
&lt;BR /&gt;
Cheers.</description>
      <pubDate>Mon, 01 Jun 2009 06:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-value-assignment-not-working/m-p/39022#M7904</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-01T06:44:52Z</dc:date>
    </item>
  </channel>
</rss>

