<?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 reduce observation and merge data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716121#M27414</link>
    <description>&lt;P&gt;If your data is sorted by id then one way:&lt;/P&gt;
&lt;PRE&gt;data table_2;
   set table_1;
   by id;
   if first.id;
run;&lt;/PRE&gt;
&lt;P&gt;When the data step uses a BY statement each variable on the statement gets two automatic temporary variables that have values 1 (true) and 0 (false) to indicate if the current observation is the First or Last of the by group. You access those with&amp;nbsp; the&amp;nbsp; First.variablename or Last.variablename construct.&lt;/P&gt;
&lt;P&gt;The IF is a subsetting if and only keeps records for the output data set where the condition is true, i.e. the first record with that value of Id.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2021 17:07:42 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-02-02T17:07:42Z</dc:date>
    <item>
      <title>How to reduce observation and merge data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716109#M27411</link>
      <description>&lt;P&gt;I have a big data where the ID repeats multiple times (table 1) in a column and I want to reduce into 1/observation (table 2). Ones the IDs are reduces to 1 per obs, I want to merge table 2 with table 3.&lt;/P&gt;
&lt;P&gt;Table 1&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the output to be&lt;/P&gt;
&lt;P&gt;Table 2&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to merge table 2 with table 3 below to have an output like table 4&lt;/P&gt;
&lt;P&gt;Table 3&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="31"&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;Visit1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;Visit2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="33"&gt;
&lt;P&gt;Visit3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="31"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;1/4/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;6/9/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="33"&gt;
&lt;P&gt;10/12/18&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="31"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;7/8/16&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="31"&gt;
&lt;P&gt;7/30/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="33"&gt;
&lt;P&gt;9/6/18&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the output to be&lt;/P&gt;
&lt;P&gt;Table 4&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;ID&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;Visit1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;Visit2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;Visit3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;1/4/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;6/9/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;10/12/18&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;7/8/16&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;7/30/18&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;9/6/18&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="75"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="83"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="106"&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716109#M27411</guid>
      <dc:creator>hjjijkkl</dc:creator>
      <dc:date>2021-02-02T16:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce observation and merge data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716111#M27412</link>
      <description>&lt;P&gt;It might be easier to skip creating Table_2 entirely:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table_4;
   merge table_1 table_3;
   by ID;
   if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course this assumes that you don't really need Table_2 as long as you can get Table_4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It requires both data sets to be in sorted order as a starting point.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 16:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716111#M27412</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-02-02T16:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce observation and merge data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716117#M27413</link>
      <description>Thanks! But, I still need table 2? Please show me how to generate table 2.</description>
      <pubDate>Tue, 02 Feb 2021 16:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716117#M27413</guid>
      <dc:creator>hjjijkkl</dc:creator>
      <dc:date>2021-02-02T16:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce observation and merge data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716121#M27414</link>
      <description>&lt;P&gt;If your data is sorted by id then one way:&lt;/P&gt;
&lt;PRE&gt;data table_2;
   set table_1;
   by id;
   if first.id;
run;&lt;/PRE&gt;
&lt;P&gt;When the data step uses a BY statement each variable on the statement gets two automatic temporary variables that have values 1 (true) and 0 (false) to indicate if the current observation is the First or Last of the by group. You access those with&amp;nbsp; the&amp;nbsp; First.variablename or Last.variablename construct.&lt;/P&gt;
&lt;P&gt;The IF is a subsetting if and only keeps records for the output data set where the condition is true, i.e. the first record with that value of Id.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 17:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-reduce-observation-and-merge-data/m-p/716121#M27414</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-02T17:07:42Z</dc:date>
    </item>
  </channel>
</rss>

