<?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: Creating a new field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810495#M319607</link>
    <description>&lt;P&gt;Do you really want to remerge the result back into all of the original observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't be more useful to just have one observation per customer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   do until (last.customer);
     set have;
     by customer ;
     length Customer_Number_Multi $200 ;
     customer_number_multi=catx(',',customer_number_multi,quote(cats(customer_number),"'"));
  end;
  keep customer customer_number_multi;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Apr 2022 20:56:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-04-28T20:56:28Z</dc:date>
    <item>
      <title>Creating a new field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810439#M319592</link>
      <description>&lt;P&gt;&lt;FONT size="3"&gt;I need help with creating a new field using values in an existing column. I have a dataset with two columns, Customer and Customer_Number. Below is a sample dataset. I need to create a new field Customer_Number_Multi using the values in the Customer_Number column. I also need single quotes&amp;nbsp;around each value and comma as a seperator. As you can see some Customers have one Customer Number and some have multiple Customer Numbers. The Customer_Number_Multi field should have all Customer_Number values for each Customer. So, for an example, for Customer ABC should have all, 123, 234 and 567 Customer_Numbers in Customer_Number_Multi. Thanks for your help.&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;Customer&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;Customer_Number&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;Customer_Number_Multi&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;ABC&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;123&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'123', '234', '567'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;ABC&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;234&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'123', '234', '567'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;ABC&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;567&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'123', '234', '567'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;DEF&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'321'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;GHI&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;345&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'345', '678'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;GHI&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;678&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'345', '678'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;JAK&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;256&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;'256'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810439#M319592</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2022-04-28T18:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810475#M319601</link>
      <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input Customer $ Customer_Number $;
    datalines;
ABC 123
ABC 234
ABC 567
DEF 321
GHI 345
GHI 678
JAK 256
    ;
run;

data intermediate;
    set have;
    length Customer_Number_Multi $32.;
    by customer;
    retain Customer_Number_Multi;
    if first.customer
        then Customer_Number_Multi = "";
    Customer_Number_Multi = catx(", ", Customer_Number_Multi, "'"||strip(customer_number)||"'");
    if last.customer;
run;

proc sql;
    create table want as
    select h.*
          ,i.Customer_Number_Multi
    from have h
    left join intermediate i
        on h.customer = i.customer;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;* Note: the code above assumes your input dataset is sorted by &lt;EM&gt;customer&lt;/EM&gt; (like your sample data) and that any duplicate&amp;nbsp;&lt;EM&gt;customer_number&lt;/EM&gt;s should be repeated in&amp;nbsp;&lt;EM&gt;customer_number_multi&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 406px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70965i2C84D8FBA884539B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 20:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810475#M319601</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2022-04-28T20:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810484#M319604</link>
      <description>Thanks for your reply. I will let you know if it works.</description>
      <pubDate>Thu, 28 Apr 2022 20:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810484#M319604</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2022-04-28T20:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810495#M319607</link>
      <description>&lt;P&gt;Do you really want to remerge the result back into all of the original observations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Wouldn't be more useful to just have one observation per customer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   do until (last.customer);
     set have;
     by customer ;
     length Customer_Number_Multi $200 ;
     customer_number_multi=catx(',',customer_number_multi,quote(cats(customer_number),"'"));
  end;
  keep customer customer_number_multi;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Apr 2022 20:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-field/m-p/810495#M319607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-28T20:56:28Z</dc:date>
    </item>
  </channel>
</rss>

