<?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: Concatenate in by statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487857#M127143</link>
    <description>I added 1. Good idea. Thank you!&lt;BR /&gt;&lt;BR /&gt;I don't understand 2 but I tried adding OUTPUT_IND = 1. The result was that it didn't even output the new data set.&lt;BR /&gt;</description>
    <pubDate>Fri, 17 Aug 2018 17:49:16 GMT</pubDate>
    <dc:creator>abak</dc:creator>
    <dc:date>2018-08-17T17:49:16Z</dc:date>
    <item>
      <title>Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487847#M127139</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to concatenate the results from one column from a data set into a single row using a by statement. The data looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;doc&amp;nbsp; operation&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; 111&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; 112&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; 119&lt;/P&gt;&lt;P&gt;14&amp;nbsp; &amp;nbsp; 823&lt;/P&gt;&lt;P&gt;14&amp;nbsp; &amp;nbsp; 1010&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And my code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data final;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;set final;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;by doc;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;retain steps;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if first.doc and last.doc then do; /*If there is only one row for the document, then*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; steps = strip(put(operation, .15)); /*The idea is to turn it into a character and strip out extra spaces*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; output; /*now output the results for this document*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end; /*end do loop*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; else then do; /*If it's not just one row per document...*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if first.doc then Steps = strip(put(operation, 15.)); /*initiate steps value with first operation*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else steps = strip(steps) || ';' || strip(operation); /*for all other steps, concatenate with a ; between values*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if last.doc then output; /* If it's the last doc, then output the results from steps */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end; /*end loop*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results, however, are an empty data set.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:17:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487847#M127139</guid>
      <dc:creator>abak</dc:creator>
      <dc:date>2018-08-17T17:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487850#M127140</link>
      <description>&lt;P&gt;I don't have a way to test anything right now, but there are two things that I would do to solve this.&lt;/P&gt;&lt;P&gt;1. Add&amp;nbsp; "length step $ 1000;"&amp;nbsp;&amp;nbsp;(or a similarity large number that will be of enough length to hold the final list)&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. replace all "OUTPUT;" with "OUTPUT_IND = 1;" so that I could see the values in&amp;nbsp;the data vector at each&amp;nbsp;row.&amp;nbsp; You can also include "put _ALL_;" at the end which will output&amp;nbsp;first.doc and last.doc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:31:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487850#M127140</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2018-08-17T17:31:10Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487851#M127141</link>
      <description>&lt;P&gt;What is your expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a complete comprehensive sample of input and expected output sample?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487851#M127141</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T17:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487854#M127142</link>
      <description>&lt;P&gt;I gave you an example of the input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;doc&amp;nbsp; operation&amp;nbsp; &amp;nbsp;steps&lt;/P&gt;&lt;P&gt;12&amp;nbsp; &amp;nbsp; 119&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 111;1112;119&lt;/P&gt;&lt;P&gt;14&amp;nbsp; &amp;nbsp; 1010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 832;1010&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487854#M127142</guid>
      <dc:creator>abak</dc:creator>
      <dc:date>2018-08-17T17:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487857#M127143</link>
      <description>I added 1. Good idea. Thank you!&lt;BR /&gt;&lt;BR /&gt;I don't understand 2 but I tried adding OUTPUT_IND = 1. The result was that it didn't even output the new data set.&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487857#M127143</guid>
      <dc:creator>abak</dc:creator>
      <dc:date>2018-08-17T17:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487861#M127144</link>
      <description>&lt;P&gt;2 is my way of troubleshooting code by removing output statements in the code.&amp;nbsp; For data steps, if there is an output somewhere in the data step, then SAS will only output the row when it hits that output statement; however, if there are on output statements in the code, then SAS will output every row when it gets to the "run;" statement.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 17:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487861#M127144</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2018-08-17T17:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487863#M127145</link>
      <description>Got it. When I don't do that it outputs nothing. Not even an empty data set. Just nothing.&lt;BR /&gt;&lt;BR /&gt;That's a good tip though that I'll remember to try again at another time when I run into complications. Thanks!&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487863#M127145</guid>
      <dc:creator>abak</dc:creator>
      <dc:date>2018-08-17T18:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487866#M127147</link>
      <description>&lt;P&gt;Does the log show that you read in rows from a dataset?&amp;nbsp; Something like&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: There were 158885 observations read from the data set WORK.FINAL&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487866#M127147</guid>
      <dc:creator>Urban_Science</dc:creator>
      <dc:date>2018-08-17T18:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487867#M127148</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input doc  operation;
cards;
12    111
12    112
12    119
14    823
14    1010
;

data want;
set have;
by doc;
length op $50;
retain op;
if first.doc then op=put(operation,8.);
else op=catx(';',op,operation);
if last.doc;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487867#M127148</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T18:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487893#M127154</link>
      <description>&lt;P&gt;Thank you for that answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone understand why mine failed though?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:49:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487893#M127154</guid>
      <dc:creator>abak</dc:creator>
      <dc:date>2018-08-17T18:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate in by statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487897#M127158</link>
      <description>&lt;P&gt;The reason yours failed is incorrect use of by group processing in a sas datastep. Just a matter of understanding this concept and you'll do fine. All the best!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 18:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-in-by-statement/m-p/487897#M127158</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T18:57:10Z</dc:date>
    </item>
  </channel>
</rss>

