<?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 Collapse occurrencies (indexes) present in multiple rows into one single row in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932241#M41919</link>
    <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Morbidity1  Morbidity2  Morbidity3  Morbidity4;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017   1    0     1    0
0001  13JAN2017 25JAN2017   1    0     1    0
0001  22FEB2017 03MAR2017   0    1     0    0
0001  30JAN2019 04MAR2019   1    0     0    0
0002  01DEC2018 14DEC2018   1    0     1    0
0002  25DEC2018 02JAN2019   0    0     1    0
0002  25NOV2020 03DEC2020   1    1     1    1
0003  09JAN2016 25JAN2016   0    0     1    0
0003  29JAN2018 12FEB2018   0    0     1    1
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to collapse all occurencies ("1" or "0") for the same ID?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let say the desired output should be:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data DB1;
  input ID :$20.  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
cards;
0001   1    1     1    0
0002   1    1     1    0
0003   0    0     1    1
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words regardless the admission-discharge specificity, the occurrencies should be collapsed into one row for each ID. Values in DB for Morbidity* variables are "1" or "0". No other values are present.&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jun 2024 17:24:14 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2024-06-13T17:24:14Z</dc:date>
    <item>
      <title>Collapse occurrencies (indexes) present in multiple rows into one single row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932241#M41919</link>
      <description>&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Admission :date09. Discharge :date09. Morbidity1  Morbidity2  Morbidity3  Morbidity4;
  format Admission date9. Discharge date9.;
cards;
0001  13JAN2017 25JAN2017   1    0     1    0
0001  13JAN2017 25JAN2017   1    0     1    0
0001  22FEB2017 03MAR2017   0    1     0    0
0001  30JAN2019 04MAR2019   1    0     0    0
0002  01DEC2018 14DEC2018   1    0     1    0
0002  25DEC2018 02JAN2019   0    0     1    0
0002  25NOV2020 03DEC2020   1    1     1    1
0003  09JAN2016 25JAN2016   0    0     1    0
0003  29JAN2018 12FEB2018   0    0     1    1
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is there a way to collapse all occurencies ("1" or "0") for the same ID?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let say the desired output should be:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data DB1;
  input ID :$20.  Morbidity1  Morbidity2  Morbidity3  Morbidity4;
cards;
0001   1    1     1    0
0002   1    1     1    0
0003   0    0     1    1
...;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In other words regardless the admission-discharge specificity, the occurrencies should be collapsed into one row for each ID. Values in DB for Morbidity* variables are "1" or "0". No other values are present.&lt;/P&gt;
&lt;P&gt;Thank you in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 17:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932241#M41919</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2024-06-13T17:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse occurrencies (indexes) present in multiple rows into one single row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932243#M41920</link>
      <description>&lt;P&gt;It looks like you want the maximum value for each of the morbidity variables within a single ID.&amp;nbsp; This is what PROC SUMMARY is for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=db ;
  by id;
  var morbidity1-morbidity4;
  output out=want (drop=_type_ _freq_)  max=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above assume DB is sorted by ID.&amp;nbsp; If not, you could:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc summary data=db nway;
  class id;
  var morbidity1-morbidity4;
  output out=want (drop=_type_ _freq_)  max=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 17:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932243#M41920</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-06-13T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Collapse occurrencies (indexes) present in multiple rows into one single row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932244#M41921</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;proc summary data=work.db nway;
   class id;
   var Morbidity: ;
   output out=work.db1 (drop=_:) max=;
run;&lt;/PRE&gt;
&lt;P&gt;NWAY means only the combination of all CLASS variables is output. Otherwise there would be a row for an all dataset summary. The Drop in the output removes two variables _type_, indicating combination of CLASS variables and _freq_ number of observations used .&lt;/P&gt;
&lt;P&gt;If you haven't seen the : list&amp;nbsp; creator it mean use all variables whose names start with the characters before the colon.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 17:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Collapse-occurrencies-indexes-present-in-multiple-rows-into-one/m-p/932244#M41921</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-13T17:42:13Z</dc:date>
    </item>
  </channel>
</rss>

