<?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 combine rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699038#M213836</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="09"x;
	input usubjid $ weight height;
	datalines;
A1	100	.
A1	.	162
A2	150	
A2	.	190
;
run;

data want;
	set have;
	by usubjid;
	retain _weight;
	*retain nonmissing values;
	if ^missing(weight) then
		_weight=weight;
	*put it back to weight variable again;
	weight=_weight;
	
	*output only last obs;
	if last.usubjid;
	drop _weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Nov 2020 05:23:39 GMT</pubDate>
    <dc:creator>hhinohar</dc:creator>
    <dc:date>2020-11-16T05:23:39Z</dc:date>
    <item>
      <title>how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699031#M213832</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2020-11-15 at 10.40.04 PM.png" style="width: 200px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51696iDC524A7C0D0A0AF9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-11-15 at 10.40.04 PM.png" alt="Screen Shot 2020-11-15 at 10.40.04 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;Could someone explain what is the best way to combine the rows with same USUBJID in the table above to make it look like the one below? I can do it using merge but I think there might be a better way. Thanks in advance for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 04:50:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699031#M213832</guid>
      <dc:creator>Amy0223</dc:creator>
      <dc:date>2020-11-16T04:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699038#M213836</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm="09"x;
	input usubjid $ weight height;
	datalines;
A1	100	.
A1	.	162
A2	150	
A2	.	190
;
run;

data want;
	set have;
	by usubjid;
	retain _weight;
	*retain nonmissing values;
	if ^missing(weight) then
		_weight=weight;
	*put it back to weight variable again;
	weight=_weight;
	
	*output only last obs;
	if last.usubjid;
	drop _weight;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 05:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699038#M213836</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-16T05:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699048#M213843</link>
      <description>&lt;P&gt;Are there always exactly two observations per usubjid? With exactly one missing data-value?&lt;/P&gt;
&lt;P&gt;If that is the case, try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   merge 
      have(keep= usubjid weight where=(not missing(weight)))
      have(keep= usubjid height where=(not missing(height)))
   ;
   by usubjid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/335263"&gt;@hhinohar&lt;/a&gt; : thanks for providing data in usable form.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 06:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699048#M213843</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-16T06:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699051#M213844</link>
      <description>&lt;P&gt;You're welcome&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 07:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699051#M213844</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-16T07:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699054#M213847</link>
      <description>&lt;P&gt;Still another way (only for numeric variables):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    usubjid,
    max(weight) as weight,
    max(height) as height
  from have
  group by usubjid
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 07:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699054#M213847</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-16T07:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699062#M213850</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265801"&gt;@Amy0223&lt;/a&gt;&amp;nbsp; Just UPDATE nonmissing values-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
	infile datalines;
	input usubjid $ weight height;
	datalines;
A1	100	.
A1	.	162
A2	150	.
A2	.	190
;
run;


data want;
 update have(obs=0) have;
 by usubjid;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Nov 2020 08:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-rows/m-p/699062#M213850</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-16T08:26:10Z</dc:date>
    </item>
  </channel>
</rss>

