<?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: solution neeeded in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523282#M142167</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA TEST;
INPUT DEPARTMENT $ PRODUCTS $;
DATALINES;
D1 X1
D1 X2
D2 Y1
D2 Y2
D2 Y3
D3 Z1
D3 Z2
D3 Z3
D3 Z4
;
RUN;

proc transpose data=test out=t(drop=_name_);
by department;
var products;
run;

data want;
set t;
length products $50;
products=catx(',',of col:);
drop col:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 22 Dec 2018 16:44:28 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-12-22T16:44:28Z</dc:date>
    <item>
      <title>solution neeeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523260#M142155</link>
      <description>&lt;P&gt;how can we print the expected output using characters function&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;BR /&gt;INPUT DEPARTMENT $ PRODUCTS $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;D1 X1&lt;BR /&gt;D1 X2&lt;BR /&gt;D2 Y1&lt;BR /&gt;D2 Y2&lt;BR /&gt;D2 Y3&lt;BR /&gt;D3 Z1&lt;BR /&gt;D3 Z2&lt;BR /&gt;D3 Z3&lt;BR /&gt;D3 Z4&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expected output&lt;/P&gt;&lt;P&gt;Department Products&lt;/P&gt;&lt;P&gt;D1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X1,X2&lt;/P&gt;&lt;P&gt;D2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y1,Y2,Y3&lt;/P&gt;&lt;P&gt;D3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Z1,Z2,Z3,Z4&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2018 12:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523260#M142155</guid>
      <dc:creator>Guptashwe</dc:creator>
      <dc:date>2018-12-22T12:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: solution neeeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523262#M142156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT DEPARTMENT $ PRODUCTS $;
DATALINES;
D1 X1
D1 X2
D2 Y1
D2 Y2
D2 Y3
D3 Z1
D3 Z2
D3 Z3
D3 Z4
;
RUN;

data want;&lt;BR /&gt;length PRODUCTS $100.;
set test(rename=(PRODUCTS=_PRODUCTS));
by DEPARTMENT  _PRODUCTS;
retain PRODUCTS;
if first.DEPARTMENT then PRODUCTS=_PRODUCTS;
else PRODUCTS=catx(',',PRODUCTS,_PRODUCTS);
if last.DEPARTMENT;
drop _PRODUCTS;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Dec 2018 13:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523262#M142156</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-22T13:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: solution neeeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523276#M142165</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT DEPARTMENT $ PRODUCTS $;
DATALINES;
D1 X1
D1 X2
D2 Y1
D2 Y2
D2 Y3
D3 Z1
D3 Z2
D3 Z3
D3 Z4
;
RUN;

data Want(rename=(products_=products));
if _n_=0 then do;
	set test;
end;
Length products_ $12.;
products_=' ';
do until(last.DEPARTMENT);
set test;
	by department;
	products_=catx(',',products_,products);
end;

drop products;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Dec 2018 15:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523276#M142165</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-12-22T15:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: solution neeeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523282#M142167</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA TEST;
INPUT DEPARTMENT $ PRODUCTS $;
DATALINES;
D1 X1
D1 X2
D2 Y1
D2 Y2
D2 Y3
D3 Z1
D3 Z2
D3 Z3
D3 Z4
;
RUN;

proc transpose data=test out=t(drop=_name_);
by department;
var products;
run;

data want;
set t;
length products $50;
products=catx(',',of col:);
drop col:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Dec 2018 16:44:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523282#M142167</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-22T16:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: solution neeeded</title>
      <link>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523309#M142174</link>
      <description>&lt;P&gt;If all you really want to do is PRINT the data, then a single DATA _NULL_ step works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
INPUT DEPARTMENT $ PRODUCTS $;
DATALINES;
D1 X1
D1 X2
D2 Y1
D2 Y2
D2 Y3
D3 Z1
D3 Z2
D3 Z3
D3 Z4
run;
data _null_;
  file print;
  set test;
  by department;
  if first.department then put / department  @5 products @;
  else put +(-1) ',' products @;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The PUT /&amp;nbsp;&amp;nbsp; says to advance a line.&lt;/LI&gt;
&lt;LI&gt;The trailing @ in a put statement tells SAS to hold the column pointer. So the next PUT statement will not automatically start a new line.&amp;nbsp; Instead it write to the location of the pointer.&lt;/LI&gt;
&lt;LI&gt;The "else put +(-1)"&amp;nbsp;ordinarily uses&amp;nbsp;the + sign to move the column pointer forward.&amp;nbsp; But in this case it's actually "+(-1)" which tells sas to move BACK one column.&amp;nbsp; That's necessary because the trailing @ after a variable name (as opposed to a character literal) actually advances one blank prior to holding the pointer.&amp;nbsp; This overwrites that blank.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sun, 23 Dec 2018 01:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/solution-neeeded/m-p/523309#M142174</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-12-23T01:07:04Z</dc:date>
    </item>
  </channel>
</rss>

