<?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 multiple observations and reduce to a single observation by category? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479492#M123795</link>
    <description>&lt;P&gt;Here are two methods:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type:$20.	brand:$20.;
datalines;
car bmw
car lexus
car toyota
car honda
car maserati
car ford
truck ford
truck chevy
truck toyota
truck dodge
motorcycle harleydavidson
motorcycle honda
;
run;
proc sort data=have;
by type;
run;
/* Method 1 */
data want(drop=brand_);
format brand $100.;
do until(last.type);
set have(rename=(brand=brand_));
by type;
brand=strip(brand)||";"||strip(brand_);
end;
run;
/* Method 2 */
proc transpose data=have out=trn(drop=_name_);
by type;
var brand;
run;
data want(drop=COL:);
set trn;
brand=CATX(";",of col:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Jul 2018 13:44:10 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-07-19T13:44:10Z</dc:date>
    <item>
      <title>How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479472#M123779</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;I have a dataset where there are multiple observations per category, and I need to reduce this dataset to a single observation per category.&lt;/P&gt;&lt;P&gt;Here is an example of my data...can someone help me code this up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;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;&lt;P&gt;data want;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;type&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;brand&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;car&lt;/TD&gt;&lt;TD&gt;bmw; lexus; toyota;honda; maserati; ford&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;truck&lt;/TD&gt;&lt;TD&gt;ford; chevy; toyota; dodge&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;motorcycle&lt;/TD&gt;&lt;TD&gt;harleydavidson; honda&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THanks&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 12:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479472#M123779</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-07-19T12:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479486#M123791</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input type	$ brand $;
cards;
car 	bmw
car 	lexus
car 	toyota
car 	honda
car 	maserati
car 	ford
truck	ford
truck	chevy
truck	toyota
truck	dodge
;
run;
data want;
length want $ 200;
 do until(last.type);
  set have;
  by type;
  want=catx(';',want,brand);
 end;
 drop brand;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:32:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479486#M123791</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-19T13:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479489#M123794</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92272"&gt;@belboy&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Can you try something like this ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods noproctitle;

proc freq data=SASHELP.CARS;
	tables  (Type) *(Make) / chisq nopercent norow nocol nocum 
		plots(only)=(freqplot mosaicplot);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:39:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479489#M123794</guid>
      <dc:creator>UdayGuntupalli</dc:creator>
      <dc:date>2018-07-19T13:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479492#M123795</link>
      <description>&lt;P&gt;Here are two methods:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type:$20.	brand:$20.;
datalines;
car bmw
car lexus
car toyota
car honda
car maserati
car ford
truck ford
truck chevy
truck toyota
truck dodge
motorcycle harleydavidson
motorcycle honda
;
run;
proc sort data=have;
by type;
run;
/* Method 1 */
data want(drop=brand_);
format brand $100.;
do until(last.type);
set have(rename=(brand=brand_));
by type;
brand=strip(brand)||";"||strip(brand_);
end;
run;
/* Method 2 */
proc transpose data=have out=trn(drop=_name_);
by type;
var brand;
run;
data want(drop=COL:);
set trn;
brand=CATX(";",of col:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479492#M123795</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-07-19T13:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479494#M123797</link>
      <description>&lt;P&gt;one more way&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length all_brand $100.;
retain all_brand;
set have;
by type;
if first.type then all_brand = brand;
else all_brand= catx(';', brand, all_brand);
if last.type then output;
drop brand;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479494#M123797</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-07-19T13:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479524#M123811</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/92272"&gt;@belboy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS Community,&lt;/P&gt;
&lt;P&gt;I have a dataset where there are multiple observations per category, and I need to reduce this dataset to a single observation per category.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What will you be doing with the resulting data? It may be harder to work with that form than you expect.&lt;/P&gt;
&lt;P&gt;For example, in your expected&amp;nbsp; want output that ford and Toyota appear in different order and positions. Anything where you need the individual names later is going to be a pain to work with. Also you example is not quite consistent about separating the names with a semicolon or semicolon and space.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;type&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;brand&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;car&lt;/TD&gt;
&lt;TD&gt;bmw; lexus; toyota;honda; maserati; ford&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;truck&lt;/TD&gt;
&lt;TD&gt;ford; chevy; toyota; dodge&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;motorcycle&lt;/TD&gt;
&lt;TD&gt;harleydavidson; honda&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 14:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479524#M123811</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-19T14:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to take multiple observations and reduce to a single observation by category?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479574#M123826</link>
      <description>&lt;P&gt;worked like a charm!&amp;nbsp; thanx&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 16:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-take-multiple-observations-and-reduce-to-a-single/m-p/479574#M123826</guid>
      <dc:creator>belboy</dc:creator>
      <dc:date>2018-07-19T16:54:16Z</dc:date>
    </item>
  </channel>
</rss>

