<?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 copy the records/observations from previous row under certain conditions? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424851#M281040</link>
    <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just realized what's wrong - i kind of omit part of the "if _n_= 0 then" statement, as i thought it is not significant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't mind can you explain what does the statement means, as you mentioned "for variable order"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for guiding me on this, really appreciate on your time and effort, as i'm really new in SAS programming and even though i went for the trainings provided by SAS, i guessed experiences of playing around with the coding still counts a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2018 08:40:21 GMT</pubDate>
    <dc:creator>Ant_K</dc:creator>
    <dc:date>2018-01-04T08:40:21Z</dc:date>
    <item>
      <title>How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424514#M281027</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, happy new year everyone. I'm a new user in using SAS program, and currently my company&amp;nbsp;is using SAS Enterprise Guide for company's management reports.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently stuck with this issue as below example, as in how to massage/amend the observ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D&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;KU1234&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Fairview Enterprise&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU1234&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Fairview Enterprise&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The scenario is, when the data/records downloaded are sorted by column &lt;STRONG&gt;"Case No"&lt;/STRONG&gt; &amp;amp; &lt;STRONG&gt;"TFC"&lt;/STRONG&gt;, those rows with &lt;STRONG&gt;TFC = "C"&lt;/STRONG&gt; (in this example, which is row 2 to row 4) will copy the observations/information from Column "&lt;STRONG&gt;Acc_No&lt;/STRONG&gt;" until "&lt;STRONG&gt;Trx&lt;/STRONG&gt;" from the very first row of the same &lt;STRONG&gt;"Case No"&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope the experts here can help this beginner here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 07:48:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424514#M281027</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-03T07:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424517#M281028</link>
      <description>&lt;P&gt;You say that only Acc_no should be manipulated, but in your example result all columns except doctype_a, case_no and tfc are changed.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 08:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424517#M281028</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-03T08:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424518#M281029</link>
      <description>&lt;P&gt;Hi Kurt, i meant from the &lt;STRONG&gt;1st column until the sixth column&lt;/STRONG&gt;, i.e. &lt;STRONG&gt;"Acc_No","Agent", "Src", "Branch_F", "Exec" &amp;amp; "Trx"&lt;/STRONG&gt; all six columns will copy from the 1st row, under the condition of same "Case No".&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 08:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424518#M281029</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-03T08:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424520#M281030</link>
      <description>&lt;P&gt;Oh, that's what you meant with "until". "up to" would have been more precise.&lt;/P&gt;
&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data preserve;
set have (keep=acc_no agent src branch_f exec trx case_no);
by case_no;
if first.case_no;
run;

data want;
update
  have
  preserve
;
by case_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jan 2018 08:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424520#M281030</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-03T08:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424521#M281031</link>
      <description>&lt;P&gt;Thanks Kurt, pardon my English and sorry for the confusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your quick response, i&amp;nbsp;will try it out.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 08:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424521#M281031</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-03T08:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424528#M281032</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm getting warning message from SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;WARNING: The MASTER data set contains more than one observation for a BY group&lt;/STRONG&gt;.&lt;/EM&gt; ( -&amp;gt; i presumed "observation" here means &lt;U&gt;row&lt;/U&gt;&amp;nbsp;in my context right?)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the programming code&amp;nbsp;didn't work as the data/records in column 1 - 6 of row 2, 3 &amp;amp; 4 still remains the same.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 10:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424528#M281032</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-03T10:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424548#M281033</link>
      <description>&lt;P&gt;Then we'll need a slightliy different approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data preserve;
set have (keep=acc_no agent src branch_f exec trx case_no);
by case_no;
if first.case_no;
run;

data want;
if _n_ = 0 then set have; * just for variable order;
merge
  have (keep=case_no doctype_a tfc)
  preserve
;
by case_no;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first step is the same, but the second replaces the update with a merge.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 11:26:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424548#M281033</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-03T11:26:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424549#M281034</link>
      <description>&lt;P&gt;The usual approach for this kind of task is to use retained variables that are set at first., but I wanted to reduce the amount of code.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 11:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424549#M281034</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-03T11:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424644#M281035</link>
      <description>&lt;P&gt;Can we assume that every CASE_NO has exactly one observation with a blank TFC, and at least one observation with a nonblank TFC?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that case, here is an approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have (where=(TFC=' ')) ;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;do until (last.case_no) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have (keep=case_no TFC DocType_A where=(TFC &amp;gt; ' ')) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2018 17:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424644#M281035</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-03T17:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424812#M281036</link>
      <description>&lt;P&gt;Hi Astounding,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply and your suggestion. But i actually have in total of 52 variables for this table, and i only wish to copy the first 6 variable's data, so is there any other&amp;nbsp;approach where i don't have to use the "keep" statement in line 5 to key in all the other 40+ variables that i want to keep?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 02:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424812#M281036</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-04T02:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424838#M281037</link>
      <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 2nd method of using "merge" still didn't work... =(&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 06:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424838#M281037</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-04T06:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424845#M281038</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184661"&gt;@Ant_K&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 2nd method of using "merge" still didn't work... =(&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It &lt;U&gt;does&lt;/U&gt; work with your example data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines4 dlm=';' dsd;
input
  acc_no :$6.
  agent :$25.
  src :$1.
  branch_f :$2.
  exec :$2.
  trx :$2.
  doctype_a
  tfc :$1.
  case_no :$7.
;
datalines4;
KU1234;Fairview Enterprise;A;KU;KU;KU;2;;ABC6345
KL4321;AMG Marine;X;KL;KL;KL;3;C;ABC6345
KL4321;AMG Marine;X;KL;KL;KL;4;C;ABC6345
KL4322;Macro Trust Fund;X;KL;KL;KL;5;C;ABC6345
;;;;
run;

data preserve;
set have (keep=acc_no agent src branch_f exec trx case_no);
by case_no;
if first.case_no;
run;

data want;
if _n_ = 0 then set have; * just for variable order;
merge
  have (keep=case_no doctype_a tfc)
  preserve
;
by case_no;
run;

proc print data=want noobs;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This result:&lt;/P&gt;
&lt;PRE&gt;                                                                   doctype_
acc_no           agent           src    branch_f    exec    trx        a       tfc    case_no

KU1234    Fairview Enterprise     A        KU        KU     KU         2              ABC6345
KU1234    Fairview Enterprise     A        KU        KU     KU         3        C     ABC6345
KU1234    Fairview Enterprise     A        KU        KU     KU         4        C     ABC6345
KU1234    Fairview Enterprise     A        KU        KU     KU         5        C     ABC6345
&lt;/PRE&gt;
&lt;P&gt;exactly matches your wanted result from your initial post.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 07:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424845#M281038</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-04T07:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424846#M281039</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184661"&gt;@Ant_K&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Astounding,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply and your suggestion. But i actually have in total of 52 variables for this table, and i only wish to copy the first 6 variable's data, so is there any other&amp;nbsp;approach where i don't have to use the "keep" statement in line 5 to key in all the other 40+ variables that i want to keep?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do it the other way around and use a drop dataset option.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 07:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424846#M281039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-04T07:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424851#M281040</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just realized what's wrong - i kind of omit part of the "if _n_= 0 then" statement, as i thought it is not significant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don't mind can you explain what does the statement means, as you mentioned "for variable order"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for guiding me on this, really appreciate on your time and effort, as i'm really new in SAS programming and even though i went for the trainings provided by SAS, i guessed experiences of playing around with the coding still counts a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 08:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424851#M281040</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-04T08:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424854#M281041</link>
      <description>&lt;P&gt;Since this set statement is conditional on _n_ = 0, it will never be &lt;EM&gt;executed&lt;/EM&gt; (_n_ starts with 1 in the first data step iteration and increments from there).&lt;/P&gt;
&lt;P&gt;But the set statement also has a &lt;EM&gt;declarative&lt;/EM&gt; character, as the data step compiler reads the dataset's metadata and uses it to set up the PDV (program data vector).&lt;/P&gt;
&lt;P&gt;Without this short line, the order of variables in the PDV (and therefore the output dataset) would be determined by the order of datasets in the merge statement, and would look different from what it was in the "have" dataset.&lt;/P&gt;
&lt;P&gt;Mind that this is purely cosmetic, the order of variables has nothing to do with their accessibility by name.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 08:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424854#M281041</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-04T08:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424864#M281042</link>
      <description>&lt;P&gt;Thanks Kurt.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 09:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424864#M281042</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-04T09:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424886#M281043</link>
      <description>&lt;P&gt;Sure. &amp;nbsp;Replace keep= with drop= and add the names of the 6 variables that you don't want to replace.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2018 12:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/424886#M281043</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-04T12:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425163#M281044</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if i would like to add in one more condition, where i only want the copying to be on those observations with variable &lt;U&gt;&lt;STRONG&gt;"TFC" not equals to null&lt;/STRONG&gt;&lt;/U&gt;? Example as below which is expand from first example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&g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D&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;CBA2134&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;No&lt;/TD&gt;&lt;TD&gt;Acc_No&lt;/TD&gt;&lt;TD&gt;Agent&lt;/TD&gt;&lt;TD&gt;Src&lt;/TD&gt;&lt;TD&gt;Branch_F&lt;/TD&gt;&lt;TD&gt;Exec&lt;/TD&gt;&lt;TD&gt;Trx&lt;/TD&gt;&lt;TD&gt;DocType_A&lt;/TD&gt;&lt;TD&gt;TFC&lt;/TD&gt;&lt;TD&gt;Case No&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;KU1234&lt;/TD&gt;&lt;TD&gt;Fairview Enterprise&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;KU&lt;/TD&gt;&lt;TD&gt;KU&lt;/TD&gt;&lt;TD&gt;KU&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU1234&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Fairview Enterprise&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU1234&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Fairview Enterprise&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU1234&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Fairview Enterprise&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;KU&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;ABC6345&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;SB9564&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;Essentials Dotcom&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;SB&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;SB&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000"&gt;SB&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;CBA2134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;KL3214&lt;/TD&gt;&lt;TD&gt;Visual Optics&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;CBA2134&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;KL3214&lt;/TD&gt;&lt;TD&gt;Visual Optics&lt;/TD&gt;&lt;TD&gt;X&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;KL&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;CBA2134&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you can see from the output results, &lt;U&gt;&lt;STRONG&gt;observations 2, 3 &amp;amp; 4&lt;/STRONG&gt; &lt;/U&gt;has changed when variable "TFC" is "C", however there are no changes to &lt;U&gt;&lt;STRONG&gt;observations 6 &amp;amp; 7&lt;/STRONG&gt;&lt;/U&gt; as "TFC" is null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you can understand my question.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 09:35:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425163#M281044</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-05T09:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425165#M281045</link>
      <description>&lt;P&gt;Please post your "have" dataset as a data step (see my example), so we have something to work with that don't requires making guesses or typing off the screen.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 09:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425165#M281045</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-05T09:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy the records/observations from previous row under certain conditions?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425496#M281046</link>
      <description>&lt;P&gt;Dear Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish i could post up the actual dataset, but because it's company's customer data and it's private and confidential, that is why i made up my own mock data and not the actual dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jan 2018 07:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-copy-the-records-observations-from-previous-row-under/m-p/425496#M281046</guid>
      <dc:creator>Ant_K</dc:creator>
      <dc:date>2018-01-06T07:05:33Z</dc:date>
    </item>
  </channel>
</rss>

