<?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: Copy the column values of a row to another row based on a specific condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904603#M357387</link>
    <description>&lt;P&gt;Another possibility is to read the dataset twice in the same data step, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by can_id;
  if first.can_id then do until(last.can_id2);
    set have(rename=(can_id=can_id2) drop=field_1-field_3);
    by can_id2;
    output;
    end;
  drop can_id2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 27 Nov 2023 07:35:39 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-11-27T07:35:39Z</dc:date>
    <item>
      <title>Copy the column values of a row to another row based on a specific condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904513#M357360</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I want to copy the column values of a row to another row based on some condition using the SAS data step or Proc SQL. I have the following data:&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE width="331"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;can_id&lt;/TD&gt;
&lt;TD width="75"&gt;date_1&lt;/TD&gt;
&lt;TD width="64"&gt;field_1&lt;/TD&gt;
&lt;TD width="64"&gt;field_2&lt;/TD&gt;
&lt;TD width="64"&gt;field_3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;11/1/2022&lt;/TD&gt;
&lt;TD&gt;char&lt;/TD&gt;
&lt;TD&gt;char&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;10/2/2023&lt;/TD&gt;
&lt;TD&gt;far&lt;/TD&gt;
&lt;TD&gt;char&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;11/28/2022&lt;/TD&gt;
&lt;TD&gt;teg&lt;/TD&gt;
&lt;TD&gt;meg&lt;/TD&gt;
&lt;TD&gt;geg&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;12/1/2022&lt;/TD&gt;
&lt;TD&gt;ham&lt;/TD&gt;
&lt;TD&gt;hjk&lt;/TD&gt;
&lt;TD&gt;sop&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;12/1/2022&lt;/TD&gt;
&lt;TD&gt;ham&lt;/TD&gt;
&lt;TD&gt;kli&lt;/TD&gt;
&lt;TD&gt;iop&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4&lt;/TD&gt;
&lt;TD&gt;1/2/2023&lt;/TD&gt;
&lt;TD&gt;jsk&lt;/TD&gt;
&lt;TD&gt;kli&lt;/TD&gt;
&lt;TD&gt;lom&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I want to copy date_1, field_1, field_2, and field_3 from the first row of the same can_id to any subsequent rows that have the same can_id.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The result I am trying to achieve looks like this:&lt;/SP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D&gt;ham&lt;/TD&gt;
&lt;TD&gt;hjk&lt;/TD&gt;
&lt;TD&gt;sop&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 25 Nov 2023 15:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904513#M357360</guid>
      <dc:creator>SP01</dc:creator>
      <dc:date>2023-11-25T15:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: Copy the column values of a row to another row based on a specific condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904518#M357362</link>
      <description>&lt;P&gt;UNTESTED CODE&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 want;
    set have;
    by can_id;
    retain field_1a field_2a field_3a;
    if first.can_id then do;   
        field1a=field_1;
        field2a=field_2;
        field3a=field_3;
    end;
    drop field_1 field_2 field_3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Nov 2023 16:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904518#M357362</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-25T16:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Copy the column values of a row to another row based on a specific condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904534#M357370</link>
      <description>&lt;P&gt;Is below returning what you're looking for?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd truncover;
  input can_id date_1:mmddyy. (field_1 field_2 field_3) (:$10.);
  format date_1 date9.;
  datalines;
1,11/1/2022,char,char, 
1,10/2/2023,far,char, 
2,11/28/2022,teg,meg,geg
3,12/1/2022,ham,hjk,sop
3,12/1/2022,ham,kli,iop
4,1/2/2023,jsk,kli,lom
;

data v_inter/view=v_inter;
  set have(keep=can_id field_1-field_3);
  by can_id;
  if first.can_id;
run;

data want;
  merge have(drop=field_1-field_3) v_inter;
  by can_id;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1700954690546.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90189i94513620BE1CA569/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1700954690546.png" alt="Patrick_0-1700954690546.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2023 23:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904534#M357370</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-25T23:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Copy the column values of a row to another row based on a specific condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904603#M357387</link>
      <description>&lt;P&gt;Another possibility is to read the dataset twice in the same data step, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by can_id;
  if first.can_id then do until(last.can_id2);
    set have(rename=(can_id=can_id2) drop=field_1-field_3);
    by can_id2;
    output;
    end;
  drop can_id2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Nov 2023 07:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copy-the-column-values-of-a-row-to-another-row-based-on-a/m-p/904603#M357387</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-11-27T07:35:39Z</dc:date>
    </item>
  </channel>
</rss>

