<?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 SAS code, please help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886737#M350379</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 is 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&amp;nbsp; description&lt;BR /&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Made of paper(F)&lt;BR /&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of Wood(A,B)&lt;BR /&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of steel (C)&lt;BR /&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Made of iron ( D)&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 22:12:13 GMT</pubDate>
    <dc:creator>Newbie_23</dc:creator>
    <dc:date>2023-07-27T22:12:13Z</dc:date>
    <item>
      <title>SAS code, please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886737#M350379</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 is 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&amp;nbsp; description&lt;BR /&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Made of paper(F)&lt;BR /&gt;12&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of Wood(A,B)&lt;BR /&gt;25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Made of steel (C)&lt;BR /&gt;15&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Made of iron ( D)&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 22:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886737#M350379</guid>
      <dc:creator>Newbie_23</dc:creator>
      <dc:date>2023-07-27T22:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code, please help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886745#M350383</link>
      <description>&lt;P&gt;Retain keep values until replaced. For your desired output you want to RESET the TYPE_CAT variable when the &lt;STRONG&gt;Description&lt;/STRONG&gt; changes not Product_id as you have multiple descriptions for the value of Product_id.&lt;/P&gt;
&lt;PRE&gt;if first.description then call missing(type_cat);&lt;/PRE&gt;
&lt;P&gt;Caution: when you append or insert values into an existing variable you have a high probability of exceeding the length of the existing variable. If your data actually has 3 values of Type associated with one of the descriptions I expect to see truncated data. The space before (, plus (), 3 letters, 2 commas and 2 spaces following the comma adds 10 characters so if the base length of the description is 11 or more then the appended value will get truncated using the existing length of Description.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider whether you actually need to append the data to the existing variable. For many purposes you may find using the variable Type_cat is more flexible. Of if that is even needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good job on provided a working data step.&lt;/P&gt;
&lt;P&gt;Better is to paste the code in either a text or code box opened using the &amp;lt;/&amp;gt; or "running man" icons above the message window to preserver formatting. The boxes also help set code apart from the discussion.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 00:15:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886745#M350383</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-28T00:15:22Z</dc:date>
    </item>
    <item>
      <title>Need better subject line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886782#M350399</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440474"&gt;@Newbie_23&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"SAS Code, please help" is not an acceptable title/subject line. Please go back to your original post (if possible) and edit the subject line so that it briefly describes the problem, as you have done in other threads.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2023 10:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-code-please-help/m-p/886782#M350399</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-28T10:14:52Z</dc:date>
    </item>
  </channel>
</rss>

