<?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: Rolling up Values and concatenate with unique description in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645318#M192891</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp; thank you for the suggestion, unfortunately a transpose isn't plausible with the data set i'm working with, this is only a snippet of the fields that are contained within this data set. There are other changing variables per previous_plan_id that cause the transpose not to function correctly. I'm looking for more of a rollup or retain function where desc= 'Consolidated' and then concatenating the fields.With this step i would have to build several transposed tables excluding several fields and then merging.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 05 May 2020 14:46:33 GMT</pubDate>
    <dc:creator>bknitch</dc:creator>
    <dc:date>2020-05-05T14:46:33Z</dc:date>
    <item>
      <title>Rolling up Values and concatenate with unique description</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645288#M192875</link>
      <description>&lt;P&gt;I have a data set of about 5k records that I need to roll-up values on and concatenate previous names and ID's to unique fields. Here is a sample of the data I have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Contract_ID&lt;/TD&gt;&lt;TD&gt;P_ID&lt;/TD&gt;&lt;TD&gt;YEAR&lt;/TD&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;PREVIOUS_P_ID&lt;/TD&gt;&lt;TD&gt;PREVIOUS_NAME&lt;/TD&gt;&lt;TD&gt;DESC&lt;/TD&gt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&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HMA_ABC&lt;/TD&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;HMA ABC-001&lt;/TD&gt;&lt;TD&gt;003&lt;/TD&gt;&lt;TD&gt;HMA ABC-003&lt;/TD&gt;&lt;TD&gt;Consolidated&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to roll-up by the Contract_ID and P_ID. I'd like to concatenate the PREVIOUS_P_ID and PREVIOUS_NAME so that they roll-up to one field. It is also important to note that this only applies to fields with a DESC = 'Consolidated'. Here is an example of what I want my end results to look like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Contract_ID&lt;/TD&gt;&lt;TD&gt;P_ID&lt;/TD&gt;&lt;TD&gt;YEAR&lt;/TD&gt;&lt;TD&gt;NAME&lt;/TD&gt;&lt;TD&gt;PREVIOUS_P_ID&lt;/TD&gt;&lt;TD&gt;PREVIOUS_NAME&lt;/TD&gt;&lt;TD&gt;DESC&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;P&lt;/TD&gt;&lt;TD&gt;PACE&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;M&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;OS&lt;/TD&gt;&lt;TD&gt;SN&lt;/TD&gt;&lt;TD&gt;DE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HMA_ABC&lt;/TD&gt;&lt;TD&gt;001&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;HMA ABC-001&lt;/TD&gt;&lt;TD&gt;001,002,003&lt;/TD&gt;&lt;TD&gt;HMA ABC-001,HMA ABC-002, HMA ABC-003&lt;/TD&gt;&lt;TD&gt;Consolidated&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 13:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645288#M192875</guid>
      <dc:creator>bknitch</dc:creator>
      <dc:date>2020-05-05T13:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling up Values and concatenate with unique description</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645304#M192880</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192500"&gt;@bknitch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to achieve this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have added a fourth row to row data to have a case where DESC is not equal to "Consolidated".&lt;/P&gt;
&lt;P&gt;Is the output correct in this case?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="09"x;
	input Contract_ID $ P_ID $ YEAR NAME:$20. PREVIOUS_P_ID $ PREVIOUS_NAME:$20. DESC:$20. H	P	PACE	D	C	M	F	OS	SN	DE;
	datalines;
HMA_ABC	001	2016	HMA ABC-001	001	HMA ABC-001	Consolidated 	1	0	0	0	0	0	0	0	0	0
HMA_ABC	001	2016	HMA ABC-001	002	HMA ABC-002	Consolidated 	1	0	0	0	0	0	0	0	0	0
HMA_ABC	001	2016	HMA ABC-001	004	HMA ABC-004	Not consolidated 	1	0	0	0	0	0	0	0	0	0
HMA_ABC	001	2016	HMA ABC-001	003	HMA ABC-003	Consolidated 	1	0	0	0	0	0	0	0	0	0
	;
run;

proc sort data=have out=have_sorted;
	by Contract_ID P_ID DESC YEAR NAME H P	PACE D	C	M	F	OS	SN	DE;
run;

proc transpose data=have_sorted out=have_tr1 (drop=_name_);
	var PREVIOUS_P_ID ;
	by Contract_ID P_ID DESC YEAR NAME H P	PACE D	C	M	F	OS	SN	DE;
run;

data want1;
	set have_tr1;
	length PREVIOUS_P_ID $100.;
	PREVIOUS_P_ID = catx(", ", of col:);
	drop col:;
run;

proc transpose data=have_sorted out=have_tr2 (drop=_name_);
	var PREVIOUS_NAME;
	by Contract_ID P_ID DESC YEAR NAME H P	PACE D	C	M	F	OS	SN	DE;
run;

data want2;
	set have_tr2;
	length PREVIOUS_NAME $100.;
	PREVIOUS_NAME = catx(", ", of col:);
	drop col:;
run;

data want;
	retain Contract_ID	P_ID YEAR NAME PREVIOUS_P_ID PREVIOUS_NAME DESC H P PACE D	C	M	F	OS	SN	DE;
	merge want1 want2;
	by Contract_ID P_ID DESC;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-05-05 à 16.10.43.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39080i747CF51E76E6184C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture d’écran 2020-05-05 à 16.10.43.png" alt="Capture d’écran 2020-05-05 à 16.10.43.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 14:12:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645304#M192880</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-05T14:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling up Values and concatenate with unique description</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645318#M192891</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp; thank you for the suggestion, unfortunately a transpose isn't plausible with the data set i'm working with, this is only a snippet of the fields that are contained within this data set. There are other changing variables per previous_plan_id that cause the transpose not to function correctly. I'm looking for more of a rollup or retain function where desc= 'Consolidated' and then concatenating the fields.With this step i would have to build several transposed tables excluding several fields and then merging.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 14:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645318#M192891</guid>
      <dc:creator>bknitch</dc:creator>
      <dc:date>2020-05-05T14:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling up Values and concatenate with unique description</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645326#M192894</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192500"&gt;@bknitch&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp; thank you for the suggestion, unfortunately a transpose isn't plausible with the data set i'm working with, this is only a snippet of the fields that are contained within this data set. There are other changing variables per previous_plan_id that cause the transpose not to function correctly. I'm looking for more of a rollup or retain function where desc= 'Consolidated' and then concatenating the fields.With this step i would have to build several transposed tables excluding several fields and then merging.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;KEEP on the variables needed for Proc transpose. The Data set option KEEP (or drop) is always available to reduce a data set:&lt;/P&gt;
&lt;P&gt;Proc transpose data=have (keep= &amp;lt;list variables needed in the transpose&amp;gt; where=(desc='Consolidated'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;lt;rest of transpose code&amp;gt;.&lt;/P&gt;
&lt;P&gt;Without rules as to how to select other variable values the result of the data would likely have to be merged back to your original.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 15:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-up-Values-and-concatenate-with-unique-description/m-p/645326#M192894</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-05T15:08:36Z</dc:date>
    </item>
  </channel>
</rss>

