<?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: new record based on condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502726#M134243</link>
    <description>&lt;P&gt;Although I'm a&amp;nbsp; "proponent of auto-merge with lead", I think this problem is more suited to Identify/Revise/Output/Reread:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.INC1;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:3.;
datalines4;
07NOV2016,02NOV2016,IDEA,10001,,,2
14NOV2016,08NOV2016,IDEA,10001,1,OVER,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;
data want;
  set inc1;
  if adj='OVER' then do;
    endt=endt-7;  /* Revise and output record */
    std=std-1;
    num=num-1;
    output;
    p=_n_;
    set inc1 point=p;  /* Reread the "over" record */
    adj=' ';           /* and modify it */
    day=.;
  end;
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, I changed variable NUM to numeric.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 14:51:41 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-10-09T14:51:41Z</dc:date>
    <item>
      <title>new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502664#M134218</link>
      <description>&lt;PRE&gt;data WORK.INC1;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:$3.;
datalines4;
07NOV2016,02NOV2016,IDEA,10001,,,2
14NOV2016,08NOV2016,IDEA,10001,1,OVER,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;


In the above test data if i have adj="OVER" then i need to create a new record before it i.e in example it is num=3 which has OVER. I need to create num=2 and 
minus number of day in num=2 whci has 07nov2016(end-day) and new record as
07NOV2016,07NOV2016,IDEA,10001,,OVER,2

data WORK.INC12;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:$3.;
datalines4;
06NOV2016,02NOV2016,IDEA,10001,,,2
07NOV2016,07NOV2016,IDEA,10001,1,OVER,2
14NOV2016,08NOV2016,IDEA,10001,,,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;&lt;/PRE&gt;
&lt;P&gt;Can anyone guide me how to get the inc12 dataset attached with input as inc1.&lt;/P&gt;
&lt;P&gt;I have made test data for 1 id but they are many id's with different menu.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 12:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502664#M134218</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-09T12:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502680#M134224</link>
      <description>&lt;P&gt;The logic is a bit tricky, but it gets the job done&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.INC1;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:$3.;
datalines4;
07NOV2016,02NOV2016,IDEA,10001,,,2
14NOV2016,08NOV2016,IDEA,10001,1,OVER,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;

data INC12;
   merge WORK.INC1 WORK.INC1(firstobs=2 keep=adj day STD rename=(adj=lead_adj day=lead_day));

   if lead_adj='OVER' then do;
      ENDT=ENDT-1;
      adj='';
      output;
      ENDT=ENDT+1;
      STD=ENDT;
      adj=lead_adj;day=lead_day;
      output;return;
   end;
   
   adj='';day=.;
   output;
   format ENDT STD lead_STD date9.;
   drop lead:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Oct 2018 13:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502680#M134224</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-09T13:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502726#M134243</link>
      <description>&lt;P&gt;Although I'm a&amp;nbsp; "proponent of auto-merge with lead", I think this problem is more suited to Identify/Revise/Output/Reread:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.INC1;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:3.;
datalines4;
07NOV2016,02NOV2016,IDEA,10001,,,2
14NOV2016,08NOV2016,IDEA,10001,1,OVER,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;
data want;
  set inc1;
  if adj='OVER' then do;
    endt=endt-7;  /* Revise and output record */
    std=std-1;
    num=num-1;
    output;
    p=_n_;
    set inc1 point=p;  /* Reread the "over" record */
    adj=' ';           /* and modify it */
    day=.;
  end;
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also, I changed variable NUM to numeric.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502726#M134243</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-09T14:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502732#M134249</link>
      <description>&lt;P&gt;Thanks a lot. Will this work no matter where the OVER record is. sometimes it can be in num 4 or num7?&lt;/P&gt;
&lt;P&gt;As i removed&amp;nbsp;firstobs=2 then it didnt work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 14:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502732#M134249</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-09T14:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502741#M134254</link>
      <description>&lt;P&gt;The firstobs=2 options has nothing to do with where the&lt;SPAN&gt;&amp;nbsp;OVER record. Pure coincidence&amp;nbsp;in this case &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So yes, it will work no matter the position.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 15:05:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/502741#M134254</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-10-09T15:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: new record based on condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/504074#M134846</link>
      <description>&lt;P&gt;It does not work in the below data as no matter what the day has value it should make a new observation. in the below data it should have a new observation in second row something like the below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;04NOV2016,02NOV2016,IDEA,10001,,,2&lt;BR /&gt;07NOV2016,05NOV2016,IDEA,10001,3,OVER,2&lt;BR /&gt;14NOV2016,08NOV2016,IDEA,10001,,,3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data WORK.INC1;
  infile datalines dsd truncover;
  input ENDT:DATE9. STD:DATE9. menu:$4. id:32. day:32. adj:$200. num:3.;
datalines4;
07NOV2016,02NOV2016,IDEA,10001,,,2
14NOV2016,08NOV2016,IDEA,10001,3,OVER,3
28NOV2016,15NOV2016,IDEA,10001,,,4
14SEP2016,29NOV2016,IDEA,10001,,,5
;;;;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2018 05:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-record-based-on-condition/m-p/504074#M134846</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-14T05:20:07Z</dc:date>
    </item>
  </channel>
</rss>

