<?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: Consolidate values from duplicate records to new variables in a single record in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586682#M14544</link>
    <description>It is also possible to do this with PROC TRANSPOSE.  If you take that approach you don't need to know NLEV.  However you would have to run it twice (once to transpose SITE and once to transpose DATE)</description>
    <pubDate>Fri, 06 Sep 2019 09:54:11 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-09-06T09:54:11Z</dc:date>
    <item>
      <title>Consolidate values from duplicate records to new variables in a single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586621#M14534</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this data set with duplicate IDs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 format id $1. site $2. date mmddyy10. nlev $1.;
 input id$ site$ date mmddyy8. nlev$;
 cards;
 A L1 01012001 1
 A L3 02022002 2
 B E3 03032003 1
 B W3 04042004 2
 B R4 05052005 3
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and I want to end up with one record per ID, but create new variables that will hold the values from the duplicate records to get something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 format id $1. site1 $2. date1 mmddyy10. site2 $2. date2 mmddyy10. site3 $2. date3 mmddyy10.;
  input id$ site1$ date1 mmddyy8. site2$ date2 mmddyy8. site3$ date3 mmddyy8.;
  cards;
  A L1 01012001 L3 02022002 . .
  B E3 03032003 W3 04042004 R4 05052005
  ;
 run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I created the NLEV variable to help me identify the duplicate IDs, but I don't need it in the final data set. Could someone give me some suggestions as to how I should go about doing this?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 05:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586621#M14534</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-09-06T05:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidate values from duplicate records to new variables in a single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586626#M14536</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288620"&gt;@bkq32&lt;/a&gt;&amp;nbsp;Hi and welcome to the SAS Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Provided that the nlev variable exists, you can do like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 format id $1. site $2. date mmddyy10. nlev $1.;
 input id$ site$ date mmddyy8. nlev$;
 cards;
 A L1 01012001 1
 A L3 02022002 2
 B E3 03032003 1
 B W3 04042004 2
 B R4 05052005 3
 ;
run;

proc sql noprint;
	select max(nlev) into :n from have;
quit;

%put &amp;amp;n.;

data want;
	do _N_=1 by 1 until (last.id);
		set have(rename=(date=_date site=_site));
		by id;
		array site{&amp;amp;n.} $2;
		array date{&amp;amp;n.};

		site[_N_]=_site;
		date[_N_]=_date;
	end;

	keep id site: date:;
	format date: mmddyyn8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 05:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586626#M14536</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-06T05:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidate values from duplicate records to new variables in a single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586682#M14544</link>
      <description>It is also possible to do this with PROC TRANSPOSE.  If you take that approach you don't need to know NLEV.  However you would have to run it twice (once to transpose SITE and once to transpose DATE)</description>
      <pubDate>Fri, 06 Sep 2019 09:54:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586682#M14544</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-09-06T09:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidate values from duplicate records to new variables in a single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586721#M14553</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 format id $1. site $2. date mmddyy10. nlev $1.;
 input id$ site$ date mmddyy8. nlev$;
 cards;
 A L1 01012001 1
 A L3 02022002 2
 B E3 03032003 1
 B W3 04042004 2
 B R4 05052005 3
 ;
run;
proc sql;
create table level as
select distinct nlev from have;
quit;

data _null_;
 set level end=last;
 if _n_=1 then call execute('data want;merge ');
 call execute(catt('have(where=(nlev="',nlev,'") 
 rename=(site=site_',nlev,' date=date_',nlev,'))'));
 if last then call execute(';by id;drop nlev;run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Sep 2019 12:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586721#M14553</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-09-06T12:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Consolidate values from duplicate records to new variables in a single record</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586825#M14589</link>
      <description>&lt;P&gt;Thank you all!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Sep 2019 17:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consolidate-values-from-duplicate-records-to-new-variables-in-a/m-p/586825#M14589</guid>
      <dc:creator>bkq32</dc:creator>
      <dc:date>2019-09-06T17:12:59Z</dc:date>
    </item>
  </channel>
</rss>

