<?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: Combining multiple rows &amp;amp; counting in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245337#M56150</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;Yes to duplicates.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Missing at the data level may cause issues but I'm assuming they could easily be filtered out with a where clause.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2016 22:45:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-01-21T22:45:58Z</dc:date>
    <item>
      <title>Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245305#M56139</link>
      <description>&lt;P&gt;Hi, I'm new to SAS, and apologize if this question has been asked elsewhere.&amp;nbsp; I have been searching previous messages for this type of work and couldn't find what I wanted.&amp;nbsp; I have a dataset that contains multiple rows per patient.&amp;nbsp; I'd like to combine all the rows for each patient, and also create an additional column with a count of how many rows were combined.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for example, I'm starting with a dataset that looks like this:&lt;/P&gt;&lt;P&gt;&lt;U&gt;patient &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fruit&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color&lt;/U&gt;&lt;/P&gt;&lt;P&gt;patientA &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; apple&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; red&lt;/P&gt;&lt;P&gt;patientA &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; banana&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; red&lt;/P&gt;&lt;P&gt;patientA &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mango &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; red&lt;/P&gt;&lt;P&gt;patientB &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; apple &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blue&lt;/P&gt;&lt;P&gt;patientC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cherry &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; green&lt;/P&gt;&lt;P&gt;patientC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grape &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; green.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I want to reorganize into a dataset that looks something like this:&lt;/P&gt;&lt;P&gt;&lt;U&gt;patient &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; count &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fruit_1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fruit_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; fruit_3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; color&lt;/U&gt;&lt;/P&gt;&lt;P&gt;patientA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 3 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; apple &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; banana &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mango &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; red&lt;/P&gt;&lt;P&gt;patientB &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; apple &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (blank) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (blank) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blue&lt;/P&gt;&lt;P&gt;patientC &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cherry &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grape &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (blank) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; green.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help.&amp;nbsp; I have been struggling with this for days, trying combinations of different lines I've been piecing together from searches.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245305#M56139</guid>
      <dc:creator>beginner</dc:creator>
      <dc:date>2016-01-21T21:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245311#M56140</link>
      <description>&lt;P&gt;You're looking to transpose your data set. You can use proc transpose or a data step and then you can count the number of missing/non missing to get your number of rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's two links with examples of transposing your data from a wide to a long format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/ltow_transpose.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/ltow_transpose.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/longtowide_data.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/longtowide_data.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245311#M56140</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T21:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245314#M56141</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana red
patientA mango  red
patientB apple  blue
patientC cherry green
patientC grape  green
;

proc transpose data=have prefix=fruit_ out=trans(drop=_name_);
by patient color;
var fruit;
run;

proc freq data=have noprint;
tables patient / out=cnt(drop=percent);
run;

data want;
merge trans cnt;
by patient;
run;
      
proc print data=want;
var patient count fruit_: color;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245314#M56141</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-21T21:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245315#M56142</link>
      <description>&lt;P&gt;Thanks so much for your fast reply, Reeza.&amp;nbsp; Sorry if this is a naive question, but how do this if my data is already in SAS as a SAS spreadsheet?&amp;nbsp; In the example you linked for the transposition, I would be typing in data as part of the command(s), right?&amp;nbsp; My dataset is really big (like 10s of columns), so I don't want to be reentering the data.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245315#M56142</guid>
      <dc:creator>beginner</dc:creator>
      <dc:date>2016-01-21T21:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245318#M56143</link>
      <description>&lt;P&gt;I've included the first data step just to create a test dataset for demonstration. With your existing dataset you would start at the PROC TRANSPOSE step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The work dataset TRANS created by PROC TRANSPOSE already contains everything you want, except for variable COUNT. The frequency counts are created by PROC FREQ and written&amp;nbsp;to&amp;nbsp;the output dataset of this procedure, which I named&amp;nbsp;CNT (and which originally contained an additional variable PERCENT, but I dropped this one, because you didn't request percentages).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Variable COUNT&amp;nbsp;and the variables from dataset TRANS are merged in the data step creating dataset WANT, using the common variable PATIENT (i.e. common to TRANS and CNT) as a key to identify matching observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, I used PROC PRINT just to show the final result.&amp;nbsp;The purpose of the VAR statement was to obtain the same column order in the output as in your example table. The internal order of the variables in the dataset is left unchanged (and irrelevant in most cases).&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:12:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245318#M56143</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-21T22:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245321#M56144</link>
      <description>&lt;P&gt;The first step is making the fake data.&lt;/P&gt;
&lt;P&gt;In the second steps where they reference faked data, you can reference your data set.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 21:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245321#M56144</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T21:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245326#M56145</link>
      <description>&lt;P&gt;Working of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;solution, but his last three steps can be simplified into one step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana red
patientA mango  red
patientB apple  blue
patientC cherry green
patientC grape  green
;

proc transpose data=have prefix=fruit_ out=trans(drop=_name_);
by patient color;
var fruit;
run;

data want;
set trans;
array fr(*) $ fruit_:;

count=dim(fr)-cmiss(of fr(*));

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245326#M56145</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T22:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245330#M56146</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;: Would your simplification produce the same result as my code, if there were missing values of&amp;nbsp;FRUIT in the HAVE dataset?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245330#M56146</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-21T22:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245332#M56147</link>
      <description>&lt;P&gt;Thank you, FreelanceReinhard.&amp;nbsp; How should I change the syntax, if I decide to remove the "color" variable from my dataset?&amp;nbsp; (E.g., will the : followed by a ; cause problems?)&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245332#M56147</guid>
      <dc:creator>beginner</dc:creator>
      <dc:date>2016-01-21T22:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245333#M56148</link>
      <description>&lt;P&gt;Drop color from proc transpose and everything should be fine. Unless you have multiples of your fruits...then you'll have an issue.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245333#M56148</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T22:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245334#M56149</link>
      <description>&lt;P&gt;The ":;" does not cause any problems. So, please feel free to delete "color" from the PROC TRANSPOSE and the PROC PRINT step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;: What do you mean by "multiples of your fruits"? Duplicate values?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245334#M56149</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-21T22:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245337#M56150</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;Yes to duplicates.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Missing at the data level may cause issues but I'm assuming they could easily be filtered out with a where clause.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 22:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245337#M56150</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T22:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245346#M56151</link>
      <description>&lt;P&gt;Maybe I'm too tired to see, but how would duplicate FRUIT values (or any other content of this variable, for that matter) interfere with the transposing?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 23:17:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245346#M56151</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-21T23:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245349#M56152</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh﻿&lt;/a&gt;&amp;nbsp;Nope, I'm too tired....I was thinking of the case when the fruit became the header, which isn't occuring in this case. So there's no issue and your code is correct &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2016 23:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245349#M56152</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-21T23:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245373#M56158</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana red
patientA mango  red
patientB apple  blue
patientC cherry green
patientC grape  green
;
proc sql;
 select max(n) into : n separated by ' '
  from (select count(*) as n from have group by patient,color);
quit;
data want;
 set have;
 by patient color;
 array x{*} $ 40 fruit1-fruit&amp;amp;n;
 retain fruit1-fruit&amp;amp;n;
 if first.color then do;n=0;call missing(of x{*});end;
 n+1;
 x{n}=fruit;
 if last.color;
 drop fruit;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jan 2016 02:50:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245373#M56158</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-01-22T02:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245383#M56160</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just in case if you require only the number of combined rows for the variable Patient ID, below code can be handy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data &lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;pat1;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;set &lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;pat;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;first.patient &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; count =&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;else&amp;nbsp; &lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;count+&lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if&amp;nbsp;&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;last.patient;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;by&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;patient;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;for Output, just click on the attachement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12227iDEC2250EC1B4CB4F/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="patient.png" title="patient.png" /&gt;</description>
      <pubDate>Fri, 22 Jan 2016 04:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245383#M56160</guid>
      <dc:creator>karthikC</dc:creator>
      <dc:date>2016-01-22T04:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245566#M56176</link>
      <description>&lt;P&gt;Thanks to all for your help!&amp;nbsp; I haven't been able to try everything you've suggested yet, but the parts I've tried so far are very helpful.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2016 22:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245566#M56176</guid>
      <dc:creator>beginner</dc:creator>
      <dc:date>2016-01-22T22:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245967#M56193</link>
      <description>&lt;P&gt;Hi, FreelanceReinhard (or others).&amp;nbsp; I think I might be encountering the problem you &amp;amp; Reeza discuss here.&amp;nbsp; If I have different values of color for any 1 patient, how would you recommend handling the situation?&amp;nbsp; In other words, is there a way to transpose multiple variables simultaneously (i.e., create new fruit_n AND create color_n columns)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 19:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245967#M56193</guid>
      <dc:creator>beginner</dc:creator>
      <dc:date>2016-01-25T19:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245970#M56195</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/69583"&gt;@beginner﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, there are several different approaches to transpose more than one variable. I learned (what I found to be) the most elegant one -- using PROC SUMMARY's IDGROUP option -- only ten days ago from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;'s posting here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/getting-multiple-rows-of-dates-for-a-subject-into-a-single-row/m-p/243643#M35172" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/getting-multiple-rows-of-dates-for-a-subject-into-a-single-row/m-p/243643#M35172&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I can write up the code if you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&lt;/P&gt;
&lt;P&gt;Here it is (borrowing the PROC SQL idea again from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp﻿&lt;/a&gt;, now from the current thread):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient $ fruit $ color $;
cards;
patientA apple  red
patientA banana pink
patientA mango  magenta
patientB apple  blue
patientC cherry green
patientC grape  lime
;

proc sql noprint;
select max(n) into :n
from (select count(*) as n from have group by patient);
quit;

proc summary data=have;
by patient;
output out=want(drop=_type_ rename=(_freq_=count)) idgroup(out[&amp;amp;n] (fruit color)=);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As an additional benefit, PROC SUMMARY computes the frequencies by default (in variable _FREQ_). So, we need neither PROC TRANSPOSE for the transposing nor PROC FREQ for the counting.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 20:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245970#M56195</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-01-25T20:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combining multiple rows &amp; counting</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245973#M56196</link>
      <description>&lt;P&gt;If you're transposing multiple variables, this macro may be of interest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset" target="_blank"&gt;http://www.sascommunity.org/wiki/A_Better_Way_to_Flip_(Transpose)_a_SAS_Dataset&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2016 20:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Combining-multiple-rows-amp-counting/m-p/245973#M56196</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-25T20:40:30Z</dc:date>
    </item>
  </channel>
</rss>

