<?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: Duplicate a line following conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116818#M24126</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a demographic projection by microsimulation. Prob_nais is the probability of giving birth. Prob_survie his the probability of survival.&lt;/P&gt;&lt;P&gt;Each observation already has a value to prob_survie. When there is a duplication (i.e. a new birth), the prob_survie change for the new observation, since it's a new born who has his own probability of survival.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once each old and new line has his own prob_survie, then I simulated mortality:&lt;/P&gt;&lt;P&gt;if rand('uniform') &amp;gt; prob_survie THEN vie=0;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 06 Jan 2013 22:31:47 GMT</pubDate>
    <dc:creator>Demographer</dc:creator>
    <dc:date>2013-01-06T22:31:47Z</dc:date>
    <item>
      <title>Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116810#M24118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;With data step, I want to duplicate a line if conditions are respected. I then change some variables on the new line created. I did this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;if&amp;nbsp; rand('uniform')&amp;lt;prob_nais then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nais=1; age=0; prob_nais=0; annee_immig=.; immig=0; duree_imm=.; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rand('uniform')&amp;gt;105/205 then do SEXE=1; prob_survie=qf; end; else do; sexe=0; prob_survie=qm; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;end; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works, but the problem is that if I add more codes after this, they aren't read properly. Example, I tried this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;test=1;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;if&amp;nbsp; rand('uniform')&amp;lt;prob_nais then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nais=1; age=0; prob_nais=0; annee_immig=.; immig=0; duree_imm=.; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rand('uniform')&amp;gt;105/205 then do SEXE=1; prob_survie=qf; end; else do; sexe=0; prob_survie=qm; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;end; &lt;/P&gt;&lt;P&gt;test2=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The variable test is created properly (all set to 1), but the variable test2 is set to missing for each observation, so I guess there is a problem with the code for the duplication.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 05 Jan 2013 23:34:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116810#M24118</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-05T23:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116811#M24119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is because of where you have placed the OUTPUT statements.&amp;nbsp; Since they are before the assignment of TEST2 the value is missing.&lt;/P&gt;&lt;P&gt;You can think of the OUTPUT statement are doing literally what its name implies.&amp;nbsp; It writes the record to that dataset with the current values of all of the variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there is a value that you want to calculate based on the current observation and have that value carried forward onto the next then use the RETAIN statement.&amp;nbsp; If you added RETAIN TEST2 statement to your data step then in this case only the first observation would have a missing value for TEST2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 01:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116811#M24119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-06T01:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116812#M24120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is there another way to duplicate a line without using the OUTPUT statements?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 20:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116812#M24120</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-06T20:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116813#M24121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nothing wrong with output statements per se.&amp;nbsp; Tom added some extra thoughts, but his initial adivce will solve your current problem.&amp;nbsp; i.e., just change your code to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; test=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; if&amp;nbsp; rand('uniform')&amp;lt;prob_nais then do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; nais=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; age=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prob_nais=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; annee_immig=.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; immig=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; duree_imm=.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rand('uniform')&amp;gt;105/205 then do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SEXE=1;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prob_survie=qf;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sexe=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prob_survie=qm;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; test2=1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 20:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116813#M24121</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-01-06T20:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116814#M24122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That doesn't work. With your code, the variable test2 is only created for observations that have been duplicated. I wrote test2=1 as an example, but I have much more codes that should follow the duplication, and those codes must concern all observations. Maybe I could just close the data step and start another one after the duplication.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 20:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116814#M24122</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-06T20:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116815#M24123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure why it would need to follow the insertion of the extra record, but if your dataset is not extremely large then there is not much harm it splitting the processing into two steps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 21:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116815#M24123</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-06T21:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116816#M24124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then I obviously don't understand what you are trying to do.&amp;nbsp; Can you post twi small example datasets, namely one that simulates what you have, and the other showing what you want the resulting dataset to look like?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 21:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116816#M24124</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-01-06T21:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116817#M24125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You must be careful about the order of statements. I think this would be better :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;test2=0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if&amp;nbsp; rand('uniform')&amp;lt;prob_nais then do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nais=1; age=0; prob_nais=0; annee_immig=.; immig=0; duree_imm=.; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if rand('uniform')&amp;gt;105/205 then do; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sexe=1; prob_survie=qf; end; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sexe=0; prob_survie=qm; end; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;STRONG&gt;test2=1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 21:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116817#M24125</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-01-06T21:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate a line following conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116818#M24126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a demographic projection by microsimulation. Prob_nais is the probability of giving birth. Prob_survie his the probability of survival.&lt;/P&gt;&lt;P&gt;Each observation already has a value to prob_survie. When there is a duplication (i.e. a new birth), the prob_survie change for the new observation, since it's a new born who has his own probability of survival.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once each old and new line has his own prob_survie, then I simulated mortality:&lt;/P&gt;&lt;P&gt;if rand('uniform') &amp;gt; prob_survie THEN vie=0;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Jan 2013 22:31:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Duplicate-a-line-following-conditions/m-p/116818#M24126</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2013-01-06T22:31:47Z</dc:date>
    </item>
  </channel>
</rss>

