<?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: Reformatting a field/variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744213#M233130</link>
    <description>I think it would work. I ran it and I think I will use the option 2. I just have to try it out using my table.&lt;BR /&gt;Thanks again for your help. I will post the update.</description>
    <pubDate>Thu, 27 May 2021 16:12:21 GMT</pubDate>
    <dc:creator>SASMom2</dc:creator>
    <dc:date>2021-05-27T16:12:21Z</dc:date>
    <item>
      <title>Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744193#M233114</link>
      <description>&lt;P&gt;I need help with an issue I am struggling with. I have a table with two variables. The ID variable is a unique identifier and the Cust_ID field is the customer IDs for the unique ID values. An ID can have one or multiple cust_ids. I want to create a third variable multi_cust_id which lists all cust_id values for each IDs. As you can see in my table below for ID '1' there are two cust_ids so the new multi_cust_id has both cust_ids listed in both lines where ID = 1. They all need a single quote surrounding them and be separated by a comma.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, how do create the multi_cust_id variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my made up table. Thanks a lot.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;Cust_id&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;multi_cust_id&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;12345&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;12345', '56789'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;56789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;12345', '56789'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23456&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;23456', '67890', '34567', '78901'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;67890&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;23456', '67890', '34567', '78901'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34567&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;23456', '67890', '34567', '78901'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;78901&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;23456', '67890', '34567', '78901'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;35678&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;35678'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23459&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34557&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54390&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34889&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2" color="#FF0000"&gt;34889'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 15:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744193#M233114</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2021-05-27T15:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744196#M233117</link>
      <description>What does your original data look like?&lt;BR /&gt;&lt;BR /&gt;Here's an example of two different ways to do this:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a" target="_blank"&gt;https://gist.github.com/statgeek/d583cfa992bf56da51d435165b07e96a&lt;/A&gt;</description>
      <pubDate>Thu, 27 May 2021 15:48:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744196#M233117</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-27T15:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744208#M233126</link>
      <description>&lt;P&gt;Thanks Reeza&lt;/P&gt;&lt;P&gt;I changed the ID values to texts. All three variables are text/string variables. Below is slightly revised table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;Cust_id&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;multi_cust_id&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;12345&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;12345', '56789'&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;56789&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;12345', '56789'&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;23456&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23456', '67890', '34567', '78901'&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;67890&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23456', '67890', '34567', '78901'&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;34567&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23456', '67890', '34567', '78901'&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;78901&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23456', '67890', '34567', '78901'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;HIJ&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;35678&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;35678'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;KLM&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;KLM&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;23459&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;KLM&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34557&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;KM&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54390&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;54321', '23459', '34557', '54390'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT size="2"&gt;NOP&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34889&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT size="2"&gt;34889'&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 27 May 2021 16:05:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744208#M233126</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2021-05-27T16:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744212#M233129</link>
      <description>&lt;P&gt;The linked solutions didn't work for you? It should generate your multi_cust_id and you can then merge that output with your original data to get what you want. You can do it in a single step with a DoW loop but that's advanced coding that's more complicated to modify and update.&lt;/P&gt;
&lt;P&gt;The types of your ID variable shouldn't matter to the code.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 16:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744212#M233129</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-27T16:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744213#M233130</link>
      <description>I think it would work. I ran it and I think I will use the option 2. I just have to try it out using my table.&lt;BR /&gt;Thanks again for your help. I will post the update.</description>
      <pubDate>Thu, 27 May 2021 16:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744213#M233130</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2021-05-27T16:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744216#M233132</link>
      <description>&lt;P&gt;I'm really curious as to how this format '123456','234567' is really useful. It seems to me adding in quotes and commas just makes it harder to deal with. But anyway ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Cust_id	$12.;
length cust_id1 $ 14;
cust_id1=quote(trim(cust_id),"'");
cards;
ABC	12345	
ABC	56789	
DEF	23456	
DEF	67890	
DEF	34567	
DEF	78901	
HIJ	35678	
KLM	54321	
KLM	23459	
KLM	34557	
KM	54390	
NOP	34889
;
proc transpose data=have out=have_t;
    by id;
    var cust_id1;
run;
data want;
    set have_t;
    multi_cust_id=catx(',',of col:);
run;
data want2;
    merge have want(keep=id multi_cust_id);
    by id;
    drop cust_id1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2021 16:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744216#M233132</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-27T16:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744223#M233136</link>
      <description>Basically, the muti_cust_id field is for reporting purpose only. At the end of the code when it creates an excel report, it lists cust_id fo each id. So, if we use cust_id field, for the ids that have mutiple cust_ids, there would be multiple lines. But if we use multi_cust_id field, there would be only one line per ID regardless on cust_ids linked to each ID.&lt;BR /&gt;&lt;BR /&gt;Hope that makes sense.</description>
      <pubDate>Thu, 27 May 2021 16:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744223#M233136</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2021-05-27T16:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744225#M233138</link>
      <description>&lt;P&gt;I think your explanation is clear, but the need to create mult_cust_id with commas and quotes seems off-target.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I read your explanation literally, the need for quotes and commas seems to disappear. You get the results with one line per ID, even if mult_cust_id is created without the quotes and without the commas. And this saves a little bit of programming to get this output, and maybe even saves more programming down the road.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 16:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744225#M233138</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-27T16:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744248#M233145</link>
      <description>&lt;P&gt;You need to make a new variable.&amp;nbsp; It needs to be long enough to hold the longest string you will generate for any of the groups.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input ID $ Cust_id $;
cards;
ABC 12345
ABC 56789
DEF 23456
DEF 67890
DEF 34567
DEF 78901
HIJ 35678
KLM 54321
KLM 23459
KLM 34557
KM  54390
NOP 34889
;

data want;
  do until (last.id);
    set have;
    by id;
    length multi_cust_id $200;
    multi_cust_id = catx(' ',multi_cust_id,cust_id);
  end;
  do until (last.id);
    set have;
    by id;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want the quotes, commas and extra spaces then change this line.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    multi_cust_id = catx(', ',multi_cust_id,quote(trim(cust_id),"'"));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Make sure to include the extra three characters generated per id when calculating how long the new variable needs to be.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 17:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744248#M233145</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-27T17:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reformatting a field/variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744270#M233157</link>
      <description>&lt;P&gt;Thanks you all for your reply. You saved me a lot of manual work in Excel.&lt;/P&gt;&lt;P&gt;I ended up using Tom's solution. It gave me exactly what I needed.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 19:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reformatting-a-field-variable/m-p/744270#M233157</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2021-05-27T19:09:02Z</dc:date>
    </item>
  </channel>
</rss>

