<?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: Identifying a combined ID var across multiple rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247401#M46386</link>
    <description>&lt;P&gt;Can you not just coalesce() the two varibales, i.e. the first non missing is the value:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  *,
          coalesce(ID1,ID2) as ID3_CALC
  from    HAVE;
quit;&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 Feb 2016 10:29:44 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-02-02T10:29:44Z</dc:date>
    <item>
      <title>Identifying a combined ID var across multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247264#M46326</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which is at the person-month level. It has 2 ID variables and a month variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1 &amp;nbsp; &amp;nbsp; ID2 &amp;nbsp; &amp;nbsp; month&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200901&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200902&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abc &amp;nbsp; &amp;nbsp; 200903&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200904&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp;200901&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp;200902&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I created a third ID variable which uses ID1 as the base ID (it doesn't look like it from the dataset above, but ID1 is more likely to be populated and cleaner than ID2). However, each row that does not have an ID1 will have the value of ID2 for the new ID variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1 &amp;nbsp; &amp;nbsp; ID2 &amp;nbsp; &amp;nbsp; month &amp;nbsp; &amp;nbsp; ID3_calc&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200901 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200902 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abc &amp;nbsp; &amp;nbsp; 200903 &amp;nbsp; &amp;nbsp; &amp;nbsp; abc&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc &amp;nbsp; &amp;nbsp; 200904 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp;200901 &amp;nbsp; &amp;nbsp; &amp;nbsp; def&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; def &amp;nbsp; &amp;nbsp; &amp;nbsp;200902 &amp;nbsp; &amp;nbsp; &amp;nbsp; def&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ultimately I put the data at the person-level, so there is one row per person with ID3_calc:&lt;/P&gt;&lt;P&gt;ID3_calc&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;abc&lt;/P&gt;&lt;P&gt;def&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is that I want to divide into 2 datasets: Dataset 2&amp;nbsp;would have all people for which ID3_calc=ID1. Dataset 3 would have all people for whom ID3_calc=ID2, but only those in which the ID2 does not appear anywhere in Dataset 1. That is, for Dataset 3, I would only want ID3_calc=def, because that person does not have any rows in Dataset 1 in which they do have a value of ID1, while ID3_calc=abc does have rows in Dataset1 under ID1=1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The people like ID3_calc=abc, for whom I have data under both their ID1 and ID2, I would want to just keep the variables based around their ID1s and delete the rows grouped by their ID2s.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 18:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247264#M46326</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2016-02-01T18:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying a combined ID var across multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247288#M46342</link>
      <description>&lt;P&gt;Well, my SQL isn't the strongest so you may need to debug this a bit.&amp;nbsp; But it does seem like a task that SQL would handle well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;/P&gt;
&lt;P&gt;create table id1_ungrouped as select * from have where (id1 &amp;gt; ' ');&lt;/P&gt;
&lt;P&gt;create table id2_ungrouped as select * from have where id1=' ' and id2 not in (select distinct id2 from id1_ungrouped);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, ID1 would be the identifier for observations in id1_ungrouped, and ID2 would be the identifier for observations in id2_ungrouped.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can follow whatever grouping steps you choose, possibly assigning id3_calc along the way if you combine the two data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 19:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247288#M46342</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-01T19:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying a combined ID var across multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247401#M46386</link>
      <description>&lt;P&gt;Can you not just coalesce() the two varibales, i.e. the first non missing is the value:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  *,
          coalesce(ID1,ID2) as ID3_CALC
  from    HAVE;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247401#M46386</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-02T10:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying a combined ID var across multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247510#M46431</link>
      <description>Perhaps I don't understand the underlying requirement, or you have selected non appropriate sample data. But, with your logic you are splitting up a homogeneous I'd in ID2 into separate id's. How can that be correct?</description>
      <pubDate>Tue, 02 Feb 2016 16:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-a-combined-ID-var-across-multiple-rows/m-p/247510#M46431</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-02-02T16:14:03Z</dc:date>
    </item>
  </channel>
</rss>

