<?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: Merge multiple records into one based on ID field in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/478814#M31068</link>
    <description>&lt;P&gt;Perfect - many thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2018 20:17:47 GMT</pubDate>
    <dc:creator>runningjay</dc:creator>
    <dc:date>2018-07-17T20:17:47Z</dc:date>
    <item>
      <title>Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476152#M30913</link>
      <description>&lt;P&gt;Really a newbie here to SAS and just getting familiar with SAS Enterprise Guide. I am trying to merge multiple records into one record based on an ID field that is in a text format. Along with the ID variables included in the csv file I imported I also have a STATE field. The STATE field provided the 2 digit state abbreviation for most of the records, but some of the records are missing this value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to merge the records to create a new dataset. For example, the current table looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="current table.jpg" style="width: 215px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21629iEC446C78270B833E/image-size/large?v=v2&amp;amp;px=999" role="button" title="current table.jpg" alt="current table.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to change this so that no record is duplicated. I would like to assign values as follows:&lt;/P&gt;&lt;P&gt;0 - All of the STATE values associated with the ID are blank.&lt;/P&gt;&lt;P&gt;1 - If the STATE value(s) associated with the record equals TX and no other value is present for the STATE field.&lt;/P&gt;&lt;P&gt;2 - If the STATE field includes one or more STATE values and none of the the STATE value(s) associated with the record equals TX.&lt;/P&gt;&lt;P&gt;3 - If the STATE field includes values for both TX and at least one other state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new table would look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="desired table.jpg" style="width: 220px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21627i8C93A35A17826551/image-size/large?v=v2&amp;amp;px=999" role="button" title="desired table.jpg" alt="desired table.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance and help would be appreciated. I don't see a way to do this using the EG wizards, but could be missing it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476152#M30913</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-07-06T20:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476153#M30914</link>
      <description>&lt;P&gt;Please post the sample as plain text for community members to easily copy paste&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476153#M30914</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-06T20:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476156#M30916</link>
      <description>&lt;P&gt;I'd like to merge the records to create a new dataset. For example, the current data looks like this:&lt;BR /&gt;&lt;BR /&gt;ID,STATE&lt;BR /&gt;KREE990001,TX&lt;BR /&gt;KREE990001,TX&lt;BR /&gt;KREE990001,&amp;nbsp; &amp;nbsp;&lt;BR /&gt;GHTR880001,&amp;nbsp; &amp;nbsp;&lt;BR /&gt;GHTR880001,&amp;nbsp; &amp;nbsp;&lt;BR /&gt;JHRT330001,NC&lt;BR /&gt;JHRT330001,&amp;nbsp; &amp;nbsp;&lt;BR /&gt;WQUT110001,TX&lt;BR /&gt;WQUT110001,OH&lt;BR /&gt;&lt;BR /&gt;However, I would like to change this so that no record is duplicated. I would like to assign values as follows:&lt;BR /&gt;&lt;BR /&gt;0 - All of the STATE values associated with the ID are blank.&lt;BR /&gt;1 - If the STATE value(s) associated with the record equals TX and no other value is present for the STATE field.&lt;BR /&gt;2 - If the STATE field includes one or more STATE values and none of the the STATE value(s) associated with the record equals TX.&lt;BR /&gt;3 - If the STATE field includes values for both TX and at least one other state.&lt;BR /&gt;&lt;BR /&gt;The new data would look like this:&lt;BR /&gt;&lt;BR /&gt;ID,STATE&lt;BR /&gt;KREE990001,1&lt;BR /&gt;GHTR880001,0&lt;BR /&gt;JHRT330001,2&lt;BR /&gt;WQUT110001,3&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 21:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476156#M30916</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-07-06T21:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476161#M30917</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';
input (ID STATE) (:$100.);
cards;
KREE990001,TX
KREE990001,TX
KREE990001,   
GHTR880001,   
GHTR880001,   
JHRT330001,NC
JHRT330001,   
WQUT110001,TX
WQUT110001,OH
;
proc sort data=have;
by id;
run;
data want;
c=0;
do n=1 by 1 until(last.id);
set have;
by id ;
if missing(state) then c+1;
if state='TX' then tx=1;
else if not missing(state) then no_tx=1;
end;
do until(last.id);
set have;
by id;
if n=c then _state=0;
else if tx and not no_tx then _state=1;
else if not tx and no_tx then _state=2;
else if tx and no_tx then _state=3;
end;
keep id _state;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs ID _state1234 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;GHTR880001&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;JHRT330001&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;KREE990001&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;WQUT110001&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 06 Jul 2018 21:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/476161#M30917</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-06T21:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477530#M31010</link>
      <description>&lt;P&gt;Solution worked perfectly - thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure if I need to post this as a new, separate question, but since it is related to the prior solution I thought I'd add it here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the problem identified, but adding one additional variable I'd like to do the same thing but unduplicate the records factoring in the additional variable. For example, the current data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID,STATE,YEAR&lt;/P&gt;&lt;P&gt;KREE990001,TX,2017&lt;/P&gt;&lt;P&gt;KREE990001,TX,2017&lt;/P&gt;&lt;P&gt;KREE990001,TX,2017&lt;/P&gt;&lt;P&gt;KREE990001,TX,2017&lt;/P&gt;&lt;P&gt;KREE990001,TX,2016&lt;/P&gt;&lt;P&gt;KREE990001,TX,2016&lt;/P&gt;&lt;P&gt;KREE990001,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GHTR880001,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GHTR880001,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JHRT330001,NC,2016&lt;/P&gt;&lt;P&gt;JHRT330001,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WQUT110001,TX,2017&lt;/P&gt;&lt;P&gt;WQUT110001,OH,2017&lt;/P&gt;&lt;P&gt;WQUT110001,OH,2017&lt;/P&gt;&lt;P&gt;WQUT110001,OH,2017&lt;/P&gt;&lt;P&gt;WQUT110001,TX,2016&lt;/P&gt;&lt;P&gt;WQUT110001,TX,2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to change this so that no record is duplicated in a single YEAR. I would like to assign values as follows taking the YEAR variable into consideration:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0 - All of the STATE values associated with the ID are blank.&lt;/P&gt;&lt;P&gt;1 - If the STATE value(s) associated with the record equals TX and no other value is present for the STATE field in that YEAR.&lt;/P&gt;&lt;P&gt;2 - If the STATE field includes one or more STATE values and none of the STATE value(s) associated with the record equals TX in that YEAR.&lt;/P&gt;&lt;P&gt;3 - If the STATE field includes values for both TX and at least one other state in that YEAR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The new data would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID,STATE,YEAR&lt;/P&gt;&lt;P&gt;KREE990001,1,2017&lt;/P&gt;&lt;P&gt;KREE990001,1,2016&lt;/P&gt;&lt;P&gt;KREE990001,0&lt;/P&gt;&lt;P&gt;GHTR880001,0&lt;/P&gt;&lt;P&gt;JHRT330001,2,2016&lt;/P&gt;&lt;P&gt;JHRT330001,0&lt;/P&gt;&lt;P&gt;WQUT110001,3,2017&lt;/P&gt;&lt;P&gt;WQUT110001,1,2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could the previous solution be modified to accomplish this or is a different method recommended?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 14:59:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477530#M31010</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-07-12T14:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477540#M31012</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88036"&gt;@runningjay&lt;/a&gt;&amp;nbsp;Sure, will give you the solution. However, I am a little busy today as I am have an exam at my college. If it;s not urgent, can you hang in there for a day plz&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477540#M31012</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-12T15:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477541#M31013</link>
      <description>&lt;P&gt;Sure - no problem. Appreciate your expertise and insight. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2018 15:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477541#M31013</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-07-12T15:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477947#M31034</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88036"&gt;@runningjay&lt;/a&gt;&amp;nbsp;First off, sorry for the delay as I was feeling very down on account of my poor performance on my college exam last night. My apologies.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok,Anyways back to question&lt;/P&gt;&lt;P&gt;Just a minor change to include year in by group processing. See if this works and let me know. Also, I wonder why you have missed values in year column. That makes it inconceivable to do any great analysis in the future using the dataset. Well!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',' truncover;
input (ID STATE) (:$50.) year ;
cards;
KREE990001,TX,2017
KREE990001,TX,2017
KREE990001,TX,2017
KREE990001,TX,2017
KREE990001,TX,2016
KREE990001,TX,2016
KREE990001,  
GHTR880001,  
GHTR880001,  
JHRT330001,NC,2016
JHRT330001,  
WQUT110001,TX,2017
WQUT110001,OH,2017
WQUT110001,OH,2017
WQUT110001,OH,2017
WQUT110001,TX,2016
WQUT110001,TX,2016
;

proc sort data=have;
by id year;
run;
data want;
c=0;
do n=1 by 1 until(last.year);
set have;
by id year;
if missing(state) then c+1;
if state='TX' then tx=1;
else if not missing(state) then no_tx=1;
end;
do until(last.year);
set have;
by id year;
if n=c then _state=0;
else if tx and not no_tx then _state=1;
else if not tx and no_tx then _state=2;
else if tx and no_tx then _state=3;
end;
keep id _state year;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 16:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/477947#M31034</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-13T16:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merge multiple records into one based on ID field</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/478814#M31068</link>
      <description>&lt;P&gt;Perfect - many thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Merge-multiple-records-into-one-based-on-ID-field/m-p/478814#M31068</guid>
      <dc:creator>runningjay</dc:creator>
      <dc:date>2018-07-17T20:17:47Z</dc:date>
    </item>
  </channel>
</rss>

