<?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-coding multiple records to match the first instance of that record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-coding-multiple-records-to-match-the-first-instance-of-that/m-p/390415#M93645</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, I can't say enough about how great this community has been. I have been sort of thrown into learning SAS and you all have made it considerably easier to get stuff done, and I've learned a lot. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, that being said, here's my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id Seq_num post_code $;
cards;
1 2 M4R
1 3 M4R
1 1 M4R
2 1 M4T
2 3 M4X
2 2 M4T
3 1 M4B
3 2 M4M
4 1 M4F
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to re-code the post-code variable so that all postal codes for a patient ID match whatever postal code is associated with seq_num=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in this case, my correctly coded dataset would look like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Patient ID     Seq_Num                Post Code
1                    2                   M4R
1                    3                   M4R
1                    1                   M4R
2                    1                   M4T
2                    3                   M4T
2                    2                   M4T
3                    1                   M4B
3                    2                   M4B
4                    1                   M4F&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm assuming there will be a data step with some sorting and some If/then statements involved, but any insights would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also if anyone knows any good reference materials to get a better understanding of data steps that would be great as well, I'd love to be able to get a better handle on this and maybe even help some people in return for all the help you have given me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2017 20:27:31 GMT</pubDate>
    <dc:creator>righcoastmike</dc:creator>
    <dc:date>2017-08-23T20:27:31Z</dc:date>
    <item>
      <title>re-coding multiple records to match the first instance of that record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-coding-multiple-records-to-match-the-first-instance-of-that/m-p/390415#M93645</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, I can't say enough about how great this community has been. I have been sort of thrown into learning SAS and you all have made it considerably easier to get stuff done, and I've learned a lot. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, that being said, here's my question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id Seq_num post_code $;
cards;
1 2 M4R
1 3 M4R
1 1 M4R
2 1 M4T
2 3 M4X
2 2 M4T
3 1 M4B
3 2 M4M
4 1 M4F
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to re-code the post-code variable so that all postal codes for a patient ID match whatever postal code is associated with seq_num=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in this case, my correctly coded dataset would look like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Patient ID     Seq_Num                Post Code
1                    2                   M4R
1                    3                   M4R
1                    1                   M4R
2                    1                   M4T
2                    3                   M4T
2                    2                   M4T
3                    1                   M4B
3                    2                   M4B
4                    1                   M4F&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm assuming there will be a data step with some sorting and some If/then statements involved, but any insights would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also if anyone knows any good reference materials to get a better understanding of data steps that would be great as well, I'd love to be able to get a better handle on this and maybe even help some people in return for all the help you have given me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2017 20:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-coding-multiple-records-to-match-the-first-instance-of-that/m-p/390415#M93645</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2017-08-23T20:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: re-coding multiple records to match the first instance of that record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-coding-multiple-records-to-match-the-first-instance-of-that/m-p/390581#M93727</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I managed to figure it out and thought I would post the answer just in case anyone has the same issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id Seq_num post_code $;
cards;&lt;BR /&gt;1 4 M4F
1 2 M4R
1 3 M4R
1 1 AAA
2 1 BBB
2 3 M4X
2 2 M4T
3 1 CCC
3 2 M4M
4 1 DDD
;
run;

proc sort;
by patient_id seq_no;
run;

data work.sorted;
set work.have;
by patient_id;
retain pcfixed;
if first.patient_id then pcfixed=post_code;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which produces an output of:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Patient_ID Seq_no Post_code pcfixed
       1      4      M4F       AAA
       1      2      M4R       AAA
       1      3      M4R       AAA
       1      1      AAA       AAA
       2      1      BBB       BBB
       2      3      M4X       BBB
       2      2      M4T       BBB
       3      1      CCC       CCC
       3      2      M4M       CCC
       4      1      DDD       DDD&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;hopefully this helps someone trying to do a similar thing in the future!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Aug 2017 12:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-coding-multiple-records-to-match-the-first-instance-of-that/m-p/390581#M93727</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2017-08-24T12:39:18Z</dc:date>
    </item>
  </channel>
</rss>

