<?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: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648584#M194322</link>
    <description>This worked perfectly. Thank you!</description>
    <pubDate>Mon, 18 May 2020 14:59:30 GMT</pubDate>
    <dc:creator>lh50</dc:creator>
    <dc:date>2020-05-18T14:59:30Z</dc:date>
    <item>
      <title>Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648571#M194316</link>
      <description>&lt;P&gt;I have a dataset where each participant received three tests, and the results of each test are in individual rows such that there are three rows for each participant. I want to collapse the rows so that each participant is represented by only one row. The data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Test1&lt;/TD&gt;&lt;TD&gt;Test2&lt;/TD&gt;&lt;TD&gt;Test3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;V04001&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;V04001&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&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t;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Test1&lt;/TD&gt;&lt;TD&gt;Test2&lt;/TD&gt;&lt;TD&gt;Test3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;V04001&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;V04002&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;V04003&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most of the searching I've done for a solution ends up with PROC TRANSPOSE, but I can't seem to figure out how to make that work with what I need. Any help would be much appreciated!&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 14:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648571#M194316</guid>
      <dc:creator>lh50</dc:creator>
      <dc:date>2020-05-18T14:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648574#M194317</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Test1	Test2	Test3;
cards;
V04001	 .	. 	0
V04001	 .	1	 .
V04001	0	 .	. 
V04002	. .	 	0
V04002	 .	0	. 
V04002	0	. .	 
V04003	 .	. 	0
V04003	 .	1	. 
V04003	1	. .	 
;


data want;
 update have(obs=0) have;
 by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 14:51:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648574#M194317</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-18T14:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648575#M194318</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/320622"&gt;@lh50&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as
	select id, sum(test1) as test1,
		   sum(test2) as test2,
		   sum(test3) as test3
	from have
	group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 14:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648575#M194318</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-18T14:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648576#M194319</link>
      <description>&lt;P&gt;If your TEST variables are all numeric then an approach with proc summary/means and the MAX function may be appropriate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc summary data = have nway;
   class id;
   var test1 test2 test3;
   output out=want (drop=_type_ _freq_) sum =;
run;&lt;/PRE&gt;
&lt;P&gt;If the values are not numeric this will not work as VAR variables in summary must be numeric.&lt;/P&gt;
&lt;P&gt;Other considerations arise if there are other variables in your data as well. Which values should be kept in the "collapsing" process would need to be specified to provide a different solution as the above will remove any other variables.&lt;/P&gt;</description>
      <pubDate>Mon, 18 May 2020 14:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648576#M194319</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-18T14:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648577#M194320</link>
      <description>&lt;P&gt;That is very easy, using the UPDATE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input ID $ test1-test3;
cards;
V04001 . . 0
V04001 . 1 . 
V04001 0 . . 
V04002 . . 0
V04002 . 0 . 
V04002 0 . . 
V04003 . . 0
V04003 . 1 . 
V04003 1 . .
;run;

data want;
  update have(obs=0) have;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 May 2020 14:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648577#M194320</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-18T14:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse multiple rows into one by unique ID, each row corresponds to value of 1 variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648584#M194322</link>
      <description>This worked perfectly. Thank you!</description>
      <pubDate>Mon, 18 May 2020 14:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Collapse-multiple-rows-into-one-by-unique-ID-each-row/m-p/648584#M194322</guid>
      <dc:creator>lh50</dc:creator>
      <dc:date>2020-05-18T14:59:30Z</dc:date>
    </item>
  </channel>
</rss>

