<?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: Applyig loop and create a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597631#M172222</link>
    <description>&lt;P&gt;Ok. But&amp;nbsp;&lt;SPAN&gt;Policy_Period&amp;nbsp;is still constant for each id? and in one of the obs,&amp;nbsp;Policy_Period=Period, correct?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2019 07:41:37 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-10-18T07:41:37Z</dc:date>
    <item>
      <title>Applyig loop and create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597626#M172219</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input ID Priod Policy_Period amount ;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 2 100&lt;BR /&gt;1 2 2 200&lt;BR /&gt;1 3 2 500&lt;BR /&gt;1 4 2 200&lt;BR /&gt;2 1 3 350&lt;BR /&gt;2 2 3 480&lt;BR /&gt;2 3 3 10&lt;BR /&gt;2 4 3 0&lt;BR /&gt;3 1 4 145&lt;BR /&gt;3 2 4 150&lt;BR /&gt;3 3 4 300&lt;BR /&gt;3 4 4 200&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I want to find the amount for the period before the&lt;BR /&gt;policy-period and the amount after the policy period for each ID.&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;input ID amount_before amount_after;&lt;BR /&gt;cards;&lt;BR /&gt;1 100 500&lt;BR /&gt;2 480 0&lt;BR /&gt;3 300 .&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 06:54:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597626#M172219</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-10-18T06:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: Applyig loop and create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597627#M172220</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(keep=ID amount_before amount_after);
    call missing(ID, amount_before, amount_after);
    do until (last.ID);
        set have;
        by ID;
        if Priod-Policy_Period = -1 then amount_before = amount;
        if Priod-Policy_Period =  1  then amount_after  = amount;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ID     amount_before  amount_after
1      100            500
2      480            0
3      300            .&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 07:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597627#M172220</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-18T07:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Applyig loop and create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597628#M172221</link>
      <description>Hi draycut,&lt;BR /&gt;&lt;BR /&gt;Thanks for the code.&lt;BR /&gt;It works well. However, not for my actual data…&lt;BR /&gt;The IDs in my actual data are not ordered as 1,2,3..that I showed here. They are 8 digit randomised numbers like 30149326,12365478 etc..&lt;BR /&gt;Is it the issue does not let the code work well?&lt;BR /&gt;Appreciate your time&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Oct 2019 07:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597628#M172221</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-10-18T07:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Applyig loop and create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597631#M172222</link>
      <description>&lt;P&gt;Ok. But&amp;nbsp;&lt;SPAN&gt;Policy_Period&amp;nbsp;is still constant for each id? and in one of the obs,&amp;nbsp;Policy_Period=Period, correct?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 07:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597631#M172222</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-18T07:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Applyig loop and create a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597645#M172229</link>
      <description>Hi again draycut,&lt;BR /&gt;&lt;BR /&gt;it was my mistake,,,&lt;BR /&gt;all good.&lt;BR /&gt;thanks again</description>
      <pubDate>Fri, 18 Oct 2019 08:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applyig-loop-and-create-a-new-variable/m-p/597645#M172229</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-10-18T08:39:05Z</dc:date>
    </item>
  </channel>
</rss>

