<?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: Inserting rows into a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593762#M170471</link>
    <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SAMPLE;
INPUT ID TIME CP;
DATALINES;
1 20 27
1 24 15
2 20 50
2 24 10
3 20 30
4 20 15
;

data want;
    set sample;
    by id;
    output;
    if first.id &amp;amp; last.id then do;
        TIME=24; CP=CP/2;
        output;
    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  time CP
1	20	 27
1	24	 15
2	20	 50
2	24	 10
3	20	 30
3	24	 15
4	20	 15
4	24	 7.5&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Oct 2019 15:03:18 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-10-03T15:03:18Z</dc:date>
    <item>
      <title>Inserting rows into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593756#M170468</link>
      <description>&lt;P&gt;I have a data set which has two time points at 20 and 24 hrs with corresponding Cp values.&amp;nbsp; However in some cases the 24 hour sample may be missing.&amp;nbsp; In those cases I would like to insert a 24 hr time sample with time=24 and cp=0.5*lag(cp) which is the current cp value at 20 hrs.&amp;nbsp; I&amp;nbsp;have written code which does not give an error but it does not work.&amp;nbsp; I need to know how to edit the code to get it to work?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SAMPLE;
INPUT ID TIME CP;
DATALINES;
1 20 27
1 24 15
2 20 50
2 24 10
3 20 30
4 20 15
;
DATA EXPAND (KEEP= ID TIME CP CP1 CP2 );
SET SAMPLE ;
TIME1=LAG(TIME);
TIME2=TIME;
CP1=CP;
CP2=LAG(CP);
OUTPUT;
DO ID=1 TO 4;
IF TIME2 = . THEN DO ;
TIME2=24;
OUTPUT;
CP1=0.5*CP2;
OUTPUT;
END;
END;
PROC PRINT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593756#M170468</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2019-10-03T14:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting rows into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593762#M170471</link>
      <description>&lt;P&gt;One way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SAMPLE;
INPUT ID TIME CP;
DATALINES;
1 20 27
1 24 15
2 20 50
2 24 10
3 20 30
4 20 15
;

data want;
    set sample;
    by id;
    output;
    if first.id &amp;amp; last.id then do;
        TIME=24; CP=CP/2;
        output;
    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  time CP
1	20	 27
1	24	 15
2	20	 50
2	24	 10
3	20	 30
3	24	 15
4	20	 15
4	24	 7.5&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 15:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593762#M170471</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-03T15:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting rows into a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593764#M170472</link>
      <description>&lt;P&gt;This?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SAMPLE;
INPUT ID TIME CP;
DATALINES;
1 20 27
1 24 15
2 20 50
2 24 10
3 20 30
4 20 15
;;;;
   run;
data want;
   set sample;
   by id;
   output;
   if last.id and time ne 24 then do;
      time = 24;
      cp = .5 *cp;
      output;
      end;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 149px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32929i403F53B99872CE3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 15:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-rows-into-a-data-set/m-p/593764#M170472</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-10-03T15:04:55Z</dc:date>
    </item>
  </channel>
</rss>

