<?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 get single row from multiple rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240223#M44292</link>
    <description>&lt;P&gt;So&amp;nbsp;&lt;SPAN&gt;Parent_ID Benefit_Code &amp;nbsp;Status_CODE &amp;nbsp;Date_of_effect &amp;nbsp;are all the same with the same Child_ID ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&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 have;
infile cards expandtabs truncover;
input Parent_ID 	Benefit_Code$ 	Status_CODE$ 	Date_of_effect :yymmdd8. 	CHILD_ID 	Entered_care : yymmdd8.;
format Date_of_effect Entered_care date9.;
cards;
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20120224
1658 	EGP 	ACT 	20120926 	1661 	20120224
;

data want;
set have;
by CHILD_ID ;
length entered_care_after_200809  $ 1;
retain entered_care_after_200809  first_entered_Care date_entered_post_200809;
if first.CHILD_ID then do;
 first_entered_Care=Entered_care;
 n=0;
 call missing(entered_care_after_200809,date_entered_post_200809);
end;
if Entered_care gt '06sep2008'd then do;
 entered_care_after_200809='Y';
 n+1;
 if n eq 1 then date_entered_post_200809=Entered_care ;
end;
if last.CHILD_ID then output;
format first_entered_Care date_entered_post_200809 date9.;
drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 21 Dec 2015 08:27:39 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2015-12-21T08:27:39Z</dc:date>
    <item>
      <title>How to get single row from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240219#M44290</link>
      <description>&lt;P&gt;Here is my sample set&amp;nbsp;records which has&amp;nbsp;parent_id and child_id&lt;/P&gt;
&lt;TABLE width="618"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="70"&gt;Parent_ID&lt;/TD&gt;
&lt;TD width="100"&gt;Benefit_Code&lt;/TD&gt;
&lt;TD width="64"&gt;Status_CODE&lt;/TD&gt;
&lt;TD width="138"&gt;Date_of_effect(DOE)&lt;/TD&gt;
&lt;TD width="87"&gt;CHILD_ID&lt;/TD&gt;
&lt;TD width="159"&gt;Entered_care(DOV)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1658&lt;/TD&gt;
&lt;TD&gt;EGP&lt;/TD&gt;
&lt;TD&gt;ACT&lt;/TD&gt;
&lt;TD&gt;20120926&lt;/TD&gt;
&lt;TD&gt;1661&lt;/TD&gt;
&lt;TD&gt;20060209&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1658&lt;/TD&gt;
&lt;TD&gt;EGP&lt;/TD&gt;
&lt;TD&gt;ACT&lt;/TD&gt;
&lt;TD&gt;20120926&lt;/TD&gt;
&lt;TD&gt;1661&lt;/TD&gt;
&lt;TD&gt;20060209&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1658&lt;/TD&gt;
&lt;TD&gt;EGP&lt;/TD&gt;
&lt;TD&gt;ACT&lt;/TD&gt;
&lt;TD&gt;20120926&lt;/TD&gt;
&lt;TD&gt;1661&lt;/TD&gt;
&lt;TD&gt;20120224&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1658&lt;/TD&gt;
&lt;TD&gt;EGP&lt;/TD&gt;
&lt;TD&gt;ACT&lt;/TD&gt;
&lt;TD&gt;20120926&lt;/TD&gt;
&lt;TD&gt;1661&lt;/TD&gt;
&lt;TD&gt;20120224&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dataset is sorted by child_id and DOV&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Conditions for get a single row are&lt;/P&gt;
&lt;P&gt;1) Child first entered care, I am using the following logic IF first.child_id then output date first_entered_Care&amp;nbsp;and it works.&lt;/P&gt;
&lt;P&gt;2) If child entered care Gt 20080906 then (add new column&amp;nbsp;as entered_care_after_200809 = 'Y') and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) If Child has multiple events after 20080906 then, output first occurence after 20080906&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SO final output should look like&lt;/P&gt;
&lt;TABLE width="1094"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="70"&gt;Parent_ID&lt;/TD&gt;
&lt;TD width="100"&gt;Benefit_Code&lt;/TD&gt;
&lt;TD width="64"&gt;Status_CODE&lt;/TD&gt;
&lt;TD width="138"&gt;Date_of_effect(DOE)&lt;/TD&gt;
&lt;TD width="87"&gt;CHILD_ID&lt;/TD&gt;
&lt;TD width="159"&gt;Date_of_variation(DOV)&lt;/TD&gt;
&lt;TD width="180"&gt;entered_care_after_200809&lt;/TD&gt;
&lt;TD width="126"&gt;first_entered_Care&lt;/TD&gt;
&lt;TD width="170"&gt;date_entered_post 200809&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1658&lt;/TD&gt;
&lt;TD&gt;EGP&lt;/TD&gt;
&lt;TD&gt;ACT&lt;/TD&gt;
&lt;TD&gt;20120926&lt;/TD&gt;
&lt;TD&gt;1661&lt;/TD&gt;
&lt;TD&gt;20120224&lt;/TD&gt;
&lt;TD&gt;Y&lt;/TD&gt;
&lt;TD&gt;20060209&lt;/TD&gt;
&lt;TD&gt;20120224&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can include all three conditions in the same do loop&lt;/P&gt;
&lt;P&gt;Any help would be appreciated&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 07:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240219#M44290</guid>
      <dc:creator>hammerman</dc:creator>
      <dc:date>2015-12-21T07:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to get single row from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240220#M44291</link>
      <description>&lt;P&gt;Please try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Parent_ID 	Benefit_Code$ 	Status_CODE$ 	Date_of_effect :yymmdd8. 	CHILD_ID 	Entered_care : yymmdd8.;
format Date_of_effect Entered_care date9.;
cards;
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20120224
1658 	EGP 	ACT 	20120926 	1661 	20120224
;

data want;
set have;
by Parent_ID Entered_care;
retain first_entered_Care;
if first.parent_id then first_entered_Care=Entered_care;
if  Entered_care &amp;gt; '06sep2008'd then do;
entered_care_after_200809 = 'Y';
date_entered_post_200809=Date_of_effect;
end;
format first_entered_Care date_entered_post_200809 date9.;
if last.parent_id and entered_care_after_200809 = 'Y';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Dec 2015 07:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240220#M44291</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-12-21T07:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get single row from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240223#M44292</link>
      <description>&lt;P&gt;So&amp;nbsp;&lt;SPAN&gt;Parent_ID Benefit_Code &amp;nbsp;Status_CODE &amp;nbsp;Date_of_effect &amp;nbsp;are all the same with the same Child_ID ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&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 have;
infile cards expandtabs truncover;
input Parent_ID 	Benefit_Code$ 	Status_CODE$ 	Date_of_effect :yymmdd8. 	CHILD_ID 	Entered_care : yymmdd8.;
format Date_of_effect Entered_care date9.;
cards;
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20060209
1658 	EGP 	ACT 	20120926 	1661 	20120224
1658 	EGP 	ACT 	20120926 	1661 	20120224
;

data want;
set have;
by CHILD_ID ;
length entered_care_after_200809  $ 1;
retain entered_care_after_200809  first_entered_Care date_entered_post_200809;
if first.CHILD_ID then do;
 first_entered_Care=Entered_care;
 n=0;
 call missing(entered_care_after_200809,date_entered_post_200809);
end;
if Entered_care gt '06sep2008'd then do;
 entered_care_after_200809='Y';
 n+1;
 if n eq 1 then date_entered_post_200809=Entered_care ;
end;
if last.CHILD_ID then output;
format first_entered_Care date_entered_post_200809 date9.;
drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Dec 2015 08:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240223#M44292</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-12-21T08:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to get single row from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240392#M44343</link>
      <description>&lt;P&gt;&amp;nbsp;It works&lt;/P&gt;
&lt;P&gt;Thanks Xia&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 04:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240392#M44343</guid>
      <dc:creator>hammerman</dc:creator>
      <dc:date>2015-12-22T04:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get single row from multiple rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240393#M44344</link>
      <description>&lt;P&gt;Hi Jagadish,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with your solution it assign all the rows with 'Y' for&amp;nbsp;entered_care_after_200809, even when the dates are not past the 20080906 date.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 04:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-single-row-from-multiple-rows/m-p/240393#M44344</guid>
      <dc:creator>hammerman</dc:creator>
      <dc:date>2015-12-22T04:46:22Z</dc:date>
    </item>
  </channel>
</rss>

