<?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: Combine multiple values into one value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587267#M167718</link>
    <description>You're entity_id is not repeated. Could you please tell me how should I&lt;BR /&gt;tweak the code now?&lt;BR /&gt;</description>
    <pubDate>Mon, 09 Sep 2019 15:08:44 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2019-09-09T15:08:44Z</dc:date>
    <item>
      <title>Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587240#M167706</link>
      <description>&lt;P&gt;I want to combine multiple values of Entity_ID into one Entity_ID in the new variable Name ENTY_NM.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I execute the code below I received 5 observations (one Entity_Id for each row ) instead of one Observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I've Entity_Ids like abc_bcf,dfe_efr then I want it to Display like abc_bcf/dfe_efr&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reqd_vars;
set dis_entity_id;
by ENTITY_ID;
length ENTY_NM $50;
retain ENTY_NM;
if first.ENTITY_ID then ENTY_NM=" ";
ENTY_NM=catx('/',ENTY_NM,ENTITY_ID);
if last.ENTITY_ID then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Sep 2019 13:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587240#M167706</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-09T13:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587250#M167712</link>
      <description>&lt;P&gt;The First. and Last. are only going help with this if the Entity_id is repeated. If it is not repeated&amp;nbsp;then each entity_id is the First and the Last and would show the behavior you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example input data.&lt;/P&gt;
&lt;P&gt;Example desired output for the given input.&lt;/P&gt;
&lt;P&gt;Rules on which ones to combine.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 14:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587250#M167712</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-09T14:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587267#M167718</link>
      <description>You're entity_id is not repeated. Could you please tell me how should I&lt;BR /&gt;tweak the code now?&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Sep 2019 15:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587267#M167718</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-09T15:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587272#M167721</link>
      <description>&lt;P&gt;Here are two methods that can be used to do this.&lt;/P&gt;
&lt;P&gt;These are full examples and you can run the code directly to see what's happening.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;You're entity_id is not repeated. Could you please tell me how should I&lt;BR /&gt;tweak the code now?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 15:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587272#M167721</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-09T15:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587295#M167735</link>
      <description>If I combine your example with mine then I do not have the variables Orgid&lt;BR /&gt;and product.&lt;BR /&gt;&lt;BR /&gt;How will you tweak your example code with only one variable STATE?&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Sep 2019 16:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587295#M167735</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-09T16:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587299#M167738</link>
      <description>You didn't provide any example so I can't combine anything or say how to modifiy your code. Please provide an example similar to mine, make fake data.</description>
      <pubDate>Mon, 09 Sep 2019 16:30:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587299#M167738</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-09T16:30:25Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587300#M167739</link>
      <description>Well, fake data as follows and both the variables which was in input and&lt;BR /&gt;output  are character.&lt;BR /&gt;&lt;BR /&gt;Entity_id&lt;BR /&gt;123456&lt;BR /&gt;78906&lt;BR /&gt;236856&lt;BR /&gt;&lt;BR /&gt;Desired result:&lt;BR /&gt;&lt;BR /&gt;Entity_ids&lt;BR /&gt;123456/78906/236856&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Sep 2019 16:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587300#M167739</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2019-09-09T16:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587303#M167740</link>
      <description>&lt;P&gt;If you'd started with this you would have had an answer hours ago &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You only need the By and first if you have multiple entity ids in the table and only want to add one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reqd_vars;
set dis_entity_id end=last_record;

by ENTITY_ID;

length ENTY_NM $50;
retain ENTY_NM;

if first.ENTITY_ID then 
ENTY_NM=catx('/',ENTY_NM,ENTITY_ID);

if last_record then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Well, fake data as follows and both the variables which was in input and&lt;BR /&gt;output are character.&lt;BR /&gt;&lt;BR /&gt;Entity_id&lt;BR /&gt;123456&lt;BR /&gt;78906&lt;BR /&gt;236856&lt;BR /&gt;&lt;BR /&gt;Desired result:&lt;BR /&gt;&lt;BR /&gt;Entity_ids&lt;BR /&gt;123456/78906/236856&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 16:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587303#M167740</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-09T16:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple values into one value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587312#M167742</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Well, fake data as follows and both the variables which was in input and&lt;BR /&gt;output are character.&lt;BR /&gt;&lt;BR /&gt;Entity_id&lt;BR /&gt;123456&lt;BR /&gt;78906&lt;BR /&gt;236856&lt;BR /&gt;&lt;BR /&gt;Desired result:&lt;BR /&gt;&lt;BR /&gt;Entity_ids&lt;BR /&gt;123456/78906/236856&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;800 posts and not providing data as a data step. &lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2019 17:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-values-into-one-value/m-p/587312#M167742</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-09T17:13:48Z</dc:date>
    </item>
  </channel>
</rss>

