<?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: concatenate customers that ID belong to in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761185#M240816</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, first, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that transforming from long to wide is generally a poor idea.&amp;nbsp; However, maybe it's for reporting or for export as a .csv file, so maybe it's worthwhile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, here's one solution, below.&amp;nbsp; The Call Missing() is probably unnecessary but is there at least in part to make it clear that the IPs are reset whenever there is a new ID.&amp;nbsp; Below the code are the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CustomerIP=1234567;

Data have;
	input ID CustomerIP;
cards;
111 1234567
222 1234567
333 8788888
444 8798777
555 8765432
222 8765432
222 7654221
111 8273774
;
Run;

PROC	SORT	DATA=Have;
	BY	ID	CustomerIP;
RUN;

DATA	Want;
	DROP		CustomerIP;
	SET	Have;
		BY	ID	CustomerIP;
	LENGTH	IPs	$32767;
	RETAIN	IPs;

	IF	FIRST.ID		THEN
		DO;
			CALL		MISSING(IPs);
			IPs		=	STRIP(PUT(CustomerIP,8.));
		END;
	ELSE
		DO;
			IPs		=	CATS(IPs,',',PUT(CustomerIP,8.));
		END;

	IF	LAST.ID;
	IF	INDEX(IPs	,	"&amp;amp;CustomerIP");
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1628783650823.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62520iC21F641ECDB3C356/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1628783650823.png" alt="jimbarbour_0-1628783650823.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 15:54:26 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2021-08-12T15:54:26Z</dc:date>
    <item>
      <title>concatenate customers that ID belong to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761059#M240760</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;User define&amp;nbsp;&lt;CODE class=" language-sas"&gt;customerIP in&amp;nbsp;a&amp;nbsp;macro&amp;nbsp;variable.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;In step1&amp;nbsp;we&amp;nbsp;check&amp;nbsp;which&amp;nbsp;ID's&amp;nbsp;belong&amp;nbsp;to&amp;nbsp;this customerIP.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;Then&amp;nbsp;we&amp;nbsp;check&amp;nbsp;for&amp;nbsp;each&amp;nbsp;ID&amp;nbsp;(from&amp;nbsp;step1)&amp;nbsp;to&amp;nbsp;which&amp;nbsp;customerIP&amp;nbsp;they&amp;nbsp;belong.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;want&amp;nbsp;to&amp;nbsp;create&amp;nbsp;a&amp;nbsp;new&amp;nbsp;field&amp;nbsp;called&amp;nbsp;vector&amp;nbsp;&amp;nbsp;that&amp;nbsp;will&amp;nbsp;concatenate&amp;nbsp;the&amp;nbsp;Custom&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;erIP's&amp;nbsp;.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;So&amp;nbsp;the&amp;nbsp;expected&amp;nbsp;results&amp;nbsp;is:&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;111 1234567,8273774&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;222&amp;nbsp;1234567,8765432,7654221&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What&amp;nbsp;is&amp;nbsp;the&amp;nbsp;way&amp;nbsp;to&amp;nbsp;get&amp;nbsp;it&amp;nbsp;please?&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let customerIP=1234567;&lt;BR /&gt;Data have;
input ID customerIP;
cards;
111 1234567
222 1234567
333 8788888
444 8798777
555 8765432
222 8765432
222 7654221
111 8273774
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 05:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761059#M240760</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-08-12T05:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate customers that ID belong to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761069#M240762</link>
      <description>&lt;P&gt;This has been discussed so many times, i am puzzled that you have found nothing adaptable to your needs.&lt;/P&gt;
&lt;P&gt;I would:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;sort have by ID&lt;/LI&gt;
&lt;LI&gt;use a data step if first/last id&lt;/LI&gt;
&lt;LI&gt;a retained variable to hold the list&lt;/LI&gt;
&lt;LI&gt;catx to fill the list&lt;/LI&gt;
&lt;LI&gt;output on last.id&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 06:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761069#M240762</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-12T06:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate customers that ID belong to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761108#M240783</link>
      <description>&lt;P&gt;To add to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt; comments, we have also discussed with you on many occasions that long is superior to wide, for almost anything you will do in SAS. Yet in the last few weeks, you are consistently asking to turn long data sets into wide. Perhaps you ought to rethink this.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 09:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761108#M240783</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-12T09:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate customers that ID belong to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761185#M240816</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, first, I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that transforming from long to wide is generally a poor idea.&amp;nbsp; However, maybe it's for reporting or for export as a .csv file, so maybe it's worthwhile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, here's one solution, below.&amp;nbsp; The Call Missing() is probably unnecessary but is there at least in part to make it clear that the IPs are reset whenever there is a new ID.&amp;nbsp; Below the code are the results.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CustomerIP=1234567;

Data have;
	input ID CustomerIP;
cards;
111 1234567
222 1234567
333 8788888
444 8798777
555 8765432
222 8765432
222 7654221
111 8273774
;
Run;

PROC	SORT	DATA=Have;
	BY	ID	CustomerIP;
RUN;

DATA	Want;
	DROP		CustomerIP;
	SET	Have;
		BY	ID	CustomerIP;
	LENGTH	IPs	$32767;
	RETAIN	IPs;

	IF	FIRST.ID		THEN
		DO;
			CALL		MISSING(IPs);
			IPs		=	STRIP(PUT(CustomerIP,8.));
		END;
	ELSE
		DO;
			IPs		=	CATS(IPs,',',PUT(CustomerIP,8.));
		END;

	IF	LAST.ID;
	IF	INDEX(IPs	,	"&amp;amp;CustomerIP");
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1628783650823.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62520iC21F641ECDB3C356/image-size/large?v=v2&amp;amp;px=999" role="button" title="jimbarbour_0-1628783650823.png" alt="jimbarbour_0-1628783650823.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 15:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761185#M240816</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-08-12T15:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate customers that ID belong to</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761189#M240818</link>
      <description>&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Aug 2021 16:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-customers-that-ID-belong-to/m-p/761189#M240818</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-12T16:00:46Z</dc:date>
    </item>
  </channel>
</rss>

