<?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: how to create a duplicate record of by a sort order and skipping a record with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537147#M147673</link>
    <description>&lt;P&gt;Isn't this the solution you looked for?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Feb 2019 18:30:07 GMT</pubDate>
    <dc:creator>Satish_Parida</dc:creator>
    <dc:date>2019-02-20T18:30:07Z</dc:date>
    <item>
      <title>how to create a duplicate record of by a sort order and skipping a record with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/536977#M147627</link>
      <description>&lt;P&gt;Dear, In the below pgm i need to create a duplicate record for &lt;FONT color="#FF6600"&gt;last.param &lt;FONT color="#000000"&gt;record only if that record has non-missing value for &lt;FONT color="#FF0000"&gt;value&amp;nbsp;&lt;FONT color="#000000"&gt;variable. If there is missing value for that record then i have to next previous record&amp;nbsp; and create duplicate record. Thank you&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;for param =a , i am able create a duplicate record by taking last.param.&amp;nbsp; But param=b, i need help in my code. thank you&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;output needed&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;id param&amp;nbsp; adt&amp;nbsp; &amp;nbsp; value&amp;nbsp; &amp;nbsp;source&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;1 a 2016-01-01 10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;original&lt;BR /&gt;1 a 2016-02-01 20&amp;nbsp; &amp;nbsp; &amp;nbsp;original&lt;BR /&gt;1 a 2016-03-01 30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;original&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF6600"&gt;1 a 2016-03-01 30&amp;nbsp; &amp;nbsp; &amp;nbsp; copy&lt;/FONT&gt;&lt;BR /&gt;1 b 2016-01-01 10&amp;nbsp; &amp;nbsp; &amp;nbsp;original&lt;BR /&gt;1 b 2016-01-04 10&amp;nbsp; &amp;nbsp; &amp;nbsp;original&lt;BR /&gt;1 b 2016-02-01 20&amp;nbsp; &amp;nbsp; &amp;nbsp;original&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#FF6600"&gt;1 b 2016-02-01 20&amp;nbsp; &amp;nbsp; &amp;nbsp;copy&lt;/FONT&gt;&lt;BR /&gt;1 b 2016-03-01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;original&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&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 have;
input id param$ adt yymmdd10. value 16-18;
format adt date9.;
datalines;
1 a 2016-01-01 10
1 a 2016-02-01 20
1 a 2016-03-01 30
1 b 2016-01-01 10
1 b 2016-01-04 10
1 b 2016-02-01 20
1 b 2016-03-01 
;
run;
proc sort data=have;
by id param adt;
run;
data want;
set have;
source='original';
 output;
 by id param adt;
 if last.param and value ^=. then do;
 source='copy';
 output;end;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Feb 2019 06:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/536977#M147627</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2019-02-20T06:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a duplicate record of by a sort order and skipping a record with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537014#M147630</link>
      <description>As you have probably seen by now, your approach adds to many copies.  While it can be fixed, it's easier to use 2 steps instead of 1.  For example, after sorting:&lt;BR /&gt;&lt;BR /&gt;data copies;&lt;BR /&gt;set have;&lt;BR /&gt;by ID param adt;&lt;BR /&gt;Where value &amp;gt; .;&lt;BR /&gt;if last.param;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have (in=original) copies;&lt;BR /&gt;by ID param adt;&lt;BR /&gt;if original then source='original';&lt;BR /&gt;else source='copy';&lt;BR /&gt;run;</description>
      <pubDate>Wed, 20 Feb 2019 09:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537014#M147630</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-20T09:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a duplicate record of by a sort order and skipping a record with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537018#M147631</link>
      <description>&lt;P&gt;Solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id param$ adt yymmdd10. value 16-18;
format adt date9.;
datalines;
1 a 2016-01-01 10
1 a 2016-02-01 20
1 a 2016-03-01 30
1 b 2016-01-01 10
1 b 2016-01-04 10
1 b 2016-02-01 20
1 b 2016-03-01 
;
run;

proc sort data=have;
by id param descending adt;
run;

data want(drop=f);
set have;
source='original';
output;
by id param descending adt;
retain f;
if first.param then f=1;
if f=1 and value ^=. then do;
	source='copy';
	output;
	f=0;
end;
run;

proc sort data=want;
by id param adt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Let us know if it worked for you.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 09:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537018#M147631</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-20T09:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a duplicate record of by a sort order and skipping a record with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537019#M147632</link>
      <description>&lt;P&gt;Please try the below code with do loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id param$ adt yymmdd10. value 16-18;
format adt date9.;
datalines;
1 a 2016-01-01 10
1 a 2016-02-01 20
1 a 2016-03-01 30
1 b 2016-01-01 10
1 b 2016-01-04 10
1 b 2016-02-01 20
1 b 2016-03-01 
;
run;


proc sort data=have;
by id param;
run;

data want;
length source $20.;
do until(last.param);
set have;
where value ne .;
by id param;
if last.param then source='copy';
ord=1;
if last.param;
output;
end;
do until(last.param);
set have;
by id param;
source='original';
ord=.;
output;
end;
run;

proc sort data=want;
by id param adt ord;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Feb 2019 09:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537019#M147632</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-02-20T09:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a duplicate record of by a sort order and skipping a record with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537147#M147673</link>
      <description>&lt;P&gt;Isn't this the solution you looked for?&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/68272"&gt;@knveraraju91&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Feb 2019 18:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-a-duplicate-record-of-by-a-sort-order-and-skipping/m-p/537147#M147673</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2019-02-20T18:30:07Z</dc:date>
    </item>
  </channel>
</rss>

