<?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: How to take values from columns and add to a single row in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886735#M350378</link>
    <description>&lt;P&gt;data have;&lt;BR /&gt;infile cards dlm=',';&lt;BR /&gt;informat product_Id $8. type $8. Description $20.;&lt;BR /&gt;input Product_ID Type Description;&lt;BR /&gt;cards;&lt;BR /&gt;12, A, Made of wood&lt;BR /&gt;12, B, Made of wood&lt;BR /&gt;25, C, Made of steel&lt;BR /&gt;15, D, Made of iron&lt;BR /&gt;12, F, Made of paper&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;BR /&gt;by product_id description type;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;length type_cat $20.;&lt;BR /&gt;by product_id description type;&lt;BR /&gt;retain type_cat;&lt;BR /&gt;if first.product_id then call missing(type_cat);&lt;BR /&gt;type_cat = catx(", ", type_cat, type);&lt;/P&gt;&lt;P&gt;if last.description then do;&lt;BR /&gt;description = catt(description, " (", type_cat, ")");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;I'm expecting output to be like shown below, please help on what am i missing.Please note that the type is added to the description within paranthesis only when description is the same between the products&lt;BR /&gt;I'm expecting output to be like shown below&lt;BR /&gt;Product_ID description&lt;BR /&gt;12 Made of paper(F)&lt;BR /&gt;12 Made of Wood(A,B)&lt;BR /&gt;25 Made of steel (C)&lt;BR /&gt;15 Made of iron ( D)&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 22:01:45 GMT</pubDate>
    <dc:creator>Newbie_23</dc:creator>
    <dc:date>2023-07-27T22:01:45Z</dc:date>
    <item>
      <title>How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886492#M350287</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a data set as shown below&lt;/P&gt;&lt;P&gt;Product_ID&amp;nbsp; &amp;nbsp; Type&amp;nbsp; &amp;nbsp; &amp;nbsp; Description&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of wood&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Made of wood&lt;/P&gt;&lt;P&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of steel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to get a dataset like the below, basically the values from Type column is added to the description within paranthesis&lt;/P&gt;&lt;P&gt;Product_ID&amp;nbsp; &amp;nbsp;Description&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of wood ( A,B)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 17:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886492#M350287</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-26T17:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886496#M350291</link>
      <description>Can the description be different if the type is different? How is that case handled?</description>
      <pubDate>Wed, 26 Jul 2023 17:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886496#M350291</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-26T17:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886497#M350292</link>
      <description>No, the description is the driver for the values to be added to the row. Please note that the description is the same for Type A and B.</description>
      <pubDate>Wed, 26 Jul 2023 17:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886497#M350292</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-26T17:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886502#M350293</link>
      <description>&lt;P&gt;Your desired output is a poor arrangement of the data in a data set, and makes further programming more difficult. Leave the data in the data set as is, don't try to re-arrange it. (Unless you want a report that looks something like what you showed, that's different).&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 17:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886502#M350293</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-26T17:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886505#M350296</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';
informat product_Id $8. type $8. Description $20.;
input Product_ID    Type      Description;
cards;
12, A, Made of wood
12, B, Made of wood
25, C, Made of steel
;;

proc sort data=have;
by product_id description type;
run;

data want;
set have;
length type_cat $20.;
by product_id description type;
retain type_cat;
if first.product_id then call missing(type_cat);
type_cat = catx(", ", type_cat, type);

if last.description then do;
description = catt(description, " (", type_cat, ")");
output;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Jul 2023 18:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886505#M350296</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-26T18:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886626#M350342</link>
      <description>&lt;P&gt;Hello Reeza,&lt;/P&gt;&lt;P&gt;Thanks for replying. But the type is added to the row only when description is the same between the products.&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 13:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886626#M350342</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-27T13:10:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886649#M350359</link>
      <description>&lt;P&gt;This is why it's a good idea to show your full output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length type_cat $20.;
by product_id description type;
retain type_cat;
if first.product_id then call missing(type_cat);
type_cat = catx(", ", type_cat, type);

if last.description and not first.description then do;
description = catt(description, " (", type_cat, ")");
output;
end;
else if last.description then output;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jul 2023 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886649#M350359</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-07-27T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886735#M350378</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;infile cards dlm=',';&lt;BR /&gt;informat product_Id $8. type $8. Description $20.;&lt;BR /&gt;input Product_ID Type Description;&lt;BR /&gt;cards;&lt;BR /&gt;12, A, Made of wood&lt;BR /&gt;12, B, Made of wood&lt;BR /&gt;25, C, Made of steel&lt;BR /&gt;15, D, Made of iron&lt;BR /&gt;12, F, Made of paper&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;BR /&gt;by product_id description type;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;length type_cat $20.;&lt;BR /&gt;by product_id description type;&lt;BR /&gt;retain type_cat;&lt;BR /&gt;if first.product_id then call missing(type_cat);&lt;BR /&gt;type_cat = catx(", ", type_cat, type);&lt;/P&gt;&lt;P&gt;if last.description then do;&lt;BR /&gt;description = catt(description, " (", type_cat, ")");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;I'm expecting output to be like shown below, please help on what am i missing.Please note that the type is added to the description within paranthesis only when description is the same between the products&lt;BR /&gt;I'm expecting output to be like shown below&lt;BR /&gt;Product_ID description&lt;BR /&gt;12 Made of paper(F)&lt;BR /&gt;12 Made of Wood(A,B)&lt;BR /&gt;25 Made of steel (C)&lt;BR /&gt;15 Made of iron ( D)&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 22:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886735#M350378</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-27T22:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886810#M350405</link>
      <description>data want;&lt;BR /&gt;set have;&lt;BR /&gt;by product_id description NOTSORTED; /* &amp;lt;-------- */&lt;BR /&gt;&lt;BR /&gt;length types $20.;&lt;BR /&gt;retain types;&lt;BR /&gt;&lt;BR /&gt;if first.description then call missing(types);&lt;BR /&gt;types = catx(", ", types, type);&lt;BR /&gt;&lt;BR /&gt;if last.description then do;&lt;BR /&gt;description = catt(description, " (", types, ")");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;keep product_id description;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Fri, 28 Jul 2023 13:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886810#M350405</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-28T13:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to take values from columns and add to a single row in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886811#M350406</link>
      <description>Thanks so much Reeza, you guided me in the right direction. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 28 Jul 2023 13:50:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-values-from-columns-and-add-to-a-single-row-in-SAS/m-p/886811#M350406</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-28T13:50:28Z</dc:date>
    </item>
  </channel>
</rss>

