<?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: Help with do loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395456#M95386</link>
    <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B;                                                                                                                                      
	S=1;                                                                                                                                      
	P=0.02;  
   
	do year=1 to 4;  
		if year=1 then s=1;
		else S=S*(1-P);                                                                                                                           
		P_marg=S*P;   
		output;
	end;                                                                                                                                        
run;                                                                                                                                         
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 13 Sep 2017 10:32:31 GMT</pubDate>
    <dc:creator>ChrisBrooks</dc:creator>
    <dc:date>2017-09-13T10:32:31Z</dc:date>
    <item>
      <title>Help with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395451#M95384</link>
      <description>&lt;P&gt;Hey everyone, I have written some codes to calculate the P_margin for 4 different years. the code and the results are shown below. But I would like to have S for year 1 eq to 1. How can I modify this code ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanx so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 391px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15081iE74F1C4FD03478E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B;                                                                                                                                      
   S=1;                                                                                                                                      
   P=0.02;                                                                                                                                   
      do year=1 to 4;                                                                                                                        
        S=S*(1-P);                                                                                                                           
        P_marg=S*P;                                                                                                                          
      output;                                                                                                                                
 end;                                                                                                                                        
run;                                                                                                                                         
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 10:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395451#M95384</guid>
      <dc:creator>Qiuyue</dc:creator>
      <dc:date>2017-09-13T10:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395456#M95386</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B;                                                                                                                                      
	S=1;                                                                                                                                      
	P=0.02;  
   
	do year=1 to 4;  
		if year=1 then s=1;
		else S=S*(1-P);                                                                                                                           
		P_marg=S*P;   
		output;
	end;                                                                                                                                        
run;                                                                                                                                         
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 10:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395456#M95386</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-13T10:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395457#M95387</link>
      <description>&lt;P&gt;How about simply&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data B;
   S=1;P=0.02;Year=1;P_marg=S*P;output;
      do year=2 to 4;
        S=S*(1-P);
        P_marg=S*P;
      output;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 10:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395457#M95387</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-09-13T10:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help with do loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395462#M95388</link>
      <description>&lt;P&gt;There's another way to interpret your request. &amp;nbsp;It's possible you want exactly the same numbers you got from your original program, but with S=1 on the first observation. &amp;nbsp;For that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data B;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; S=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; P=0.02;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do year=1 to 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;S=S*(1-P);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if year=1 then replacement_S=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;else replacement_S = S;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;P_marg = S * P;&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;&amp;nbsp; drop S;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; rename replacement_S = S;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 10:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-do-loop/m-p/395462#M95388</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-13T10:45:32Z</dc:date>
    </item>
  </channel>
</rss>

