<?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 flat filing in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635507#M78068</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which includes patients that have all had "X" specific heart condition, with multiple rows per for the same patient id (ptid). Each row is an admission to the hospital. I am trying to count the # of admissions for X (the hear condition) and flatten the file so there is one row per patient id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of my data currently:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADMID PTID&amp;nbsp; &amp;nbsp;HRTCON&amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;6573&amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02MAR2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;4359&amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07JUN2004&lt;/P&gt;&lt;P&gt;7893&amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12DEC2004&lt;/P&gt;&lt;P&gt;&amp;nbsp;8989&amp;nbsp; &amp;nbsp; &amp;nbsp;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05APR2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;0542&amp;nbsp; &amp;nbsp; &amp;nbsp;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09MAY2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to end up with as a FINAL dataset:&lt;/P&gt;&lt;P&gt;PTID HRTCON&amp;nbsp; COUNT&lt;/P&gt;&lt;P&gt;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end goal is to determine the number of patients that were admitted one or more times for this heart condition. Here is the code I've tried so far to flatten the file (but this has not worked to flattened the file according to ptid):&lt;/P&gt;&lt;P&gt;proc means data=admhrt noprint;&lt;BR /&gt;class ptid;&lt;BR /&gt;types ptid;&lt;BR /&gt;output out=heart1 n(ptid)=count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data heart2;&lt;BR /&gt;set admhrt;&lt;BR /&gt;by ptid;&lt;BR /&gt;if first.ptid then count=0;&lt;BR /&gt;count=count+1;&lt;BR /&gt;if last.ptid then output;&lt;BR /&gt;retain count;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Mar 2020 13:59:46 GMT</pubDate>
    <dc:creator>monsterpie</dc:creator>
    <dc:date>2020-03-28T13:59:46Z</dc:date>
    <item>
      <title>flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635507#M78068</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which includes patients that have all had "X" specific heart condition, with multiple rows per for the same patient id (ptid). Each row is an admission to the hospital. I am trying to count the # of admissions for X (the hear condition) and flatten the file so there is one row per patient id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of my data currently:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ADMID PTID&amp;nbsp; &amp;nbsp;HRTCON&amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&lt;/P&gt;&lt;P&gt;&amp;nbsp;6573&amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 02MAR2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;4359&amp;nbsp; &amp;nbsp; &amp;nbsp;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 07JUN2004&lt;/P&gt;&lt;P&gt;7893&amp;nbsp; &amp;nbsp; &amp;nbsp; 01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12DEC2004&lt;/P&gt;&lt;P&gt;&amp;nbsp;8989&amp;nbsp; &amp;nbsp; &amp;nbsp;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 05APR2003&lt;/P&gt;&lt;P&gt;&amp;nbsp;0542&amp;nbsp; &amp;nbsp; &amp;nbsp;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 09MAY2005&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to end up with as a FINAL dataset:&lt;/P&gt;&lt;P&gt;PTID HRTCON&amp;nbsp; COUNT&lt;/P&gt;&lt;P&gt;01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My end goal is to determine the number of patients that were admitted one or more times for this heart condition. Here is the code I've tried so far to flatten the file (but this has not worked to flattened the file according to ptid):&lt;/P&gt;&lt;P&gt;proc means data=admhrt noprint;&lt;BR /&gt;class ptid;&lt;BR /&gt;types ptid;&lt;BR /&gt;output out=heart1 n(ptid)=count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data heart2;&lt;BR /&gt;set admhrt;&lt;BR /&gt;by ptid;&lt;BR /&gt;if first.ptid then count=0;&lt;BR /&gt;count=count+1;&lt;BR /&gt;if last.ptid then output;&lt;BR /&gt;retain count;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Mar 2020 13:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635507#M78068</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2020-03-28T13:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635508#M78069</link>
      <description>Hi,&lt;BR /&gt;start with PROC SQL and aggregation by PTID, e.g.:&lt;BR /&gt;&lt;BR /&gt;select PTID, HRTCON, count(1) as COUNT from DATA where HRTCON = 'X' group by PTID;&lt;BR /&gt;&lt;BR /&gt;All the best&lt;BR /&gt;Bart</description>
      <pubDate>Sat, 28 Mar 2020 14:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635508#M78069</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-28T14:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635509#M78070</link>
      <description>Hi Bart,&lt;BR /&gt;Thank you for your help! I will try out this solution. I am also wondering though if there is a way to do this using proc means or the datastep I've showed? I thought both those would work so I'm just wondering if there was something wrong with my code.</description>
      <pubDate>Sat, 28 Mar 2020 14:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635509#M78070</guid>
      <dc:creator>monsterpie</dc:creator>
      <dc:date>2020-03-28T14:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635513#M78072</link>
      <description>The code you provided looks ok? I'm not sure what is the issue?&lt;BR /&gt;All the best&lt;BR /&gt;Bart</description>
      <pubDate>Sat, 28 Mar 2020 14:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635513#M78072</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-28T14:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635517#M78074</link>
      <description>&lt;P&gt;Are you looking for something like the following?:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data admhrt;
  input ADMID PTID $  HRTCON  $  DATE date9.;
  cards;
6573     01            X            02MAR2003
4359     01            X            07JUN2004
7893     01            X            12DEC2004
7894     01            Y            13dec2004
7895     01            Y            14dec2004
8989     02            X            05APR2003
0542     02            X            09MAY2005
;
run;

proc means data=admhrt (where=(hrtcon eq 'X')) nway noprint;
  class ptid hrtcon;
  output out=heart1 (drop=_:) n=count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 28 Mar 2020 15:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635517#M78074</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2020-03-28T15:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: flat filing</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635572#M78079</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318138"&gt;@monsterpie&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the datastep: Just make sure that you retain the count variable and also only count rows where&amp;nbsp;HRTCON='X'. You could amend your datastep code with one of below options:&lt;/P&gt;
&lt;PRE&gt;/* option 1 */
if HRTCON='X' then count=count+1;

/* option 2 */
count+(HRTCON='X');&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 01:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/flat-filing/m-p/635572#M78079</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-29T01:27:59Z</dc:date>
    </item>
  </channel>
</rss>

