<?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: limit array to look at the first occurence of event in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45675#M9451</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure what you are asking.&amp;nbsp; Your question concerned a 0 then 1 combination, but your added code is looking for a 1 then missing combo.&amp;nbsp; You also said that you wanted the second date, but never asked for dischargedt(i+1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statements could be combined:&lt;/P&gt;&lt;P style="background-color: #eef4f9;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hospitA&lt;I&gt;=1 and (hospitA[i+1]=0 or missing(hospitA[i+1])) then disch_dt=dichargedt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #eef4f9;"&gt;However, again, I'm not sure what you are asking.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Nov 2011 01:52:41 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-11-11T01:52:41Z</dc:date>
    <item>
      <title>limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45666#M9442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I used array to create a wide dataset from the long one using following statement: &lt;/P&gt;&lt;P&gt;data hospb; &lt;/P&gt;&lt;P&gt;&amp;nbsp; set hospa; &lt;/P&gt;&lt;P&gt;&amp;nbsp; array oldfirst(4)fst_dt1-fst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array oldlast(4)lst_dt1-lst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospit(4) hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain fst_dt1-fst_dt4 lst_dt1-lst_dt4 hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; *array oldlast(*)lst_dt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; *array new(*) admdt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.id then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to 4; &lt;/P&gt;&lt;P&gt;&amp;nbsp; oldfirst(i)=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; oldlast(i)=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; hospit(i)=.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp; oldfirst(count)=fst_dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; oldlast(count)=lst_dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; hospit(count)=hosp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.id then output; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;THis is the how the data looks like &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Obs&lt;BR /&gt;id fst_dt1 fst_dt2 fst_dt3 fst_dt4 lst_dt1 lst_dt2 lst_dt3 lst_dt4 hosp_1 hosp_2 hosp_3 hosp_4&lt;BR /&gt;1 1 01JAN2010 02JAN2010 03JAN2010 05FEB2011 02JAN2010 03JAN2010 05JAN2010 06FEB2011 1 1 1 0&lt;BR /&gt;2 2 03FEB2011 09FEB2011 . . 07FEB2011 09FEB2011 . . 1 0 . .&lt;BR /&gt;3 3 03FEB2011 04MAR2011 . . 03FEB2011 05MAR2011 . . 0 1 . .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I need now is to look for some patterns: if hospitalization is =0 and then next one is =1 then that date is assigned to the admission date. &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;Likewise where 1 is followed by 0 it is assigned to discharge date. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;I was pretty successful with that step using following program: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;array admissiondt(4) fst_dt1-fst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dichargedt(4) lst_dt1-lst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospitA (4) hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i =1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then disch_dt=dichargedt(i); &lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;but where I am running into problem is assigning admission date to the first record if there are more than one record with hosp=1. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;For the record 1 I am getting admission rate assigned to the third observation. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New;"&gt;Any help is appreciated. &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 21:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45666#M9442</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-10T21:02:47Z</dc:date>
    </item>
    <item>
      <title>limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45667#M9443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to tell us more.&amp;nbsp; I'm not sure what you mean by "if there are more than one record with hosp=1".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From your example it looks like there is only one record per id and the code appears to be assigning values correctly according to your specifications.&amp;nbsp; When I ran your code, the first record only got disch_dt assigned and it was assigned, per specs, to the 3rd observation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In short, we must be missing something.&amp;nbsp; Rather than provide how you created the file, it would help to see a datastep with the data you are now working with, along with the full code (rather than just a snippet) showing how you are trying to modify it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 21:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45667#M9443</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-10T21:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45668#M9444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your reply. &lt;/P&gt;&lt;P&gt;Here is the datastep for the original dataset: &lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hosp; &lt;/P&gt;&lt;P&gt;INPUT id pos fst_dt mmddyy11. lst_dt mmddyy11.&lt;BR /&gt;drg;&lt;/P&gt;&lt;P&gt;datalines&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;001 2 01/01/2010 01/02/2010 001&lt;/P&gt;&lt;P&gt;001 3 01/02/2010 01/03/2010 001&lt;/P&gt;&lt;P&gt;001 2 01/03/2010 01/05/2010 002&lt;/P&gt;&lt;P&gt;001 2 02/05/2011 02/06/2011 . &lt;/P&gt;&lt;P&gt;002 3 02/03/2011 02/07/2011 003&lt;/P&gt;&lt;P&gt;002 4 02/09/2011 02/09/2011 .&lt;/P&gt;&lt;P&gt;003 4 02/03/2011 02/03/2011 .&lt;/P&gt;&lt;P&gt;003 1 03/04/2011 03/05/2011 003&lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Then I created hospitalization flag. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hosp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; format fst_dt lst_dt admdt dichdt date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospitalization(*)hosp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array newq(*)dichdt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array oldfirst(*)fst_dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array oldlast(*)lst_dt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; array new(*)admdt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=1 to dim(new); &lt;/P&gt;&lt;P&gt;&amp;nbsp; if pos in (1 2 3) and drg ^=. then hospitalization(i)=1; &lt;/P&gt;&lt;P&gt;&amp;nbsp; else hospitalization(i)=0; &lt;/P&gt;&lt;P&gt;&amp;nbsp; retain hosp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format fst_dt lst_dt admdt date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the data is transposed using arrays (in my original post), the first person will have four records, where the first three hosp=1. &lt;/P&gt;&lt;P&gt;when I add &lt;/P&gt;&lt;P&gt;" if hospitA&lt;I&gt;=1 and hospitA[i+1]=1 then adm_dt=admissiondt(i); "&lt;/I&gt;&lt;/P&gt;&lt;P&gt;I am getting the third date instead of first one. &lt;/P&gt;&lt;P&gt;Hopefully I made myself clear?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 21:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45668#M9444</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-10T21:41:19Z</dc:date>
    </item>
    <item>
      <title>limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45669#M9445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Need to see a complete set of code that runs.&amp;nbsp; In the code you initially posted, to do the transposition, it uses at least one variable (count) that doesn't exist.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 21:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45669#M9445</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-10T21:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45670#M9446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Sorry about this, I am new to this community. &lt;/P&gt;&lt;P&gt;Here is the entire code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data hosp; &lt;BR /&gt; INPUT id pos&amp;nbsp; fst_dt mmddyy11. lst_dt mmddyy11. drg;&lt;BR /&gt; datalines ;&lt;BR /&gt; 001 2 01/01/2010 01/02/2010 001&lt;BR /&gt;001 3 01/02/2010 01/03/2010 001&lt;BR /&gt;001 2 01/03/2010 01/05/2010 002&lt;BR /&gt;001 2 02/05/2011 02/06/2011 . &lt;BR /&gt;002 3 02/03/2011 02/07/2011 003&lt;BR /&gt;002 4 02/09/2011 02/09/2011 .&lt;BR /&gt;003 4 02/03/2011 02/03/2011 .&lt;BR /&gt;003 1 03/04/2011 03/05/2011 003&lt;/P&gt;&lt;P&gt;; &lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; set hosp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; format fst_dt lst_dt admdt dichdt date9.;&lt;BR /&gt;&amp;nbsp; array hospitalization(*)hosp;&lt;BR /&gt;&amp;nbsp; array newq(*)dichdt;&lt;BR /&gt;&amp;nbsp; array oldfirst(*)fst_dt;&lt;BR /&gt;&amp;nbsp; array oldlast(*)lst_dt; &lt;BR /&gt;&amp;nbsp; array new(*)admdt;&lt;BR /&gt;&amp;nbsp; do i=1 to dim(new); &lt;BR /&gt;&amp;nbsp; if pos in (1 2 3) and drg ^=. then hospitalization(i)=1; &lt;BR /&gt;&amp;nbsp; else hospitalization(i)=0; &lt;BR /&gt;&amp;nbsp; retain hosp; &lt;BR /&gt;&amp;nbsp; end; &lt;BR /&gt;&amp;nbsp; proc print; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format fst_dt lst_dt admdt date9.;&lt;BR /&gt;&amp;nbsp; run;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; data hospa; &lt;BR /&gt;&amp;nbsp; set want; &lt;BR /&gt;&amp;nbsp; retain count;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;&amp;nbsp; if first.id then count = 0;&lt;BR /&gt;&amp;nbsp; count = count + 1;&lt;BR /&gt;&amp;nbsp; proc print; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format fst_dt lst_dt admdt date9.;&lt;BR /&gt;&amp;nbsp; run;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; data hospb; &lt;BR /&gt;&amp;nbsp; set hospa; &lt;BR /&gt;&amp;nbsp; array oldfirst(4)fst_dt1-fst_dt4;&lt;BR /&gt;&amp;nbsp; array oldlast(4)lst_dt1-lst_dt4;&lt;BR /&gt;&amp;nbsp; array hospit(4) hosp_1-hosp_4;&lt;BR /&gt;&amp;nbsp; retain fst_dt1-fst_dt4 lst_dt1-lst_dt4 hosp_1-hosp_4;&lt;BR /&gt;&amp;nbsp; by id;&lt;BR /&gt;&amp;nbsp; if first.id then do;&lt;BR /&gt;&amp;nbsp; do i=1 to 4; &lt;BR /&gt;&amp;nbsp; oldfirst(i)=.;&lt;BR /&gt;&amp;nbsp; oldlast(i)=.;&lt;BR /&gt;&amp;nbsp; hospit(i)=.;&lt;BR /&gt;&amp;nbsp; end; &lt;BR /&gt;&amp;nbsp; end; &lt;BR /&gt;&amp;nbsp; oldfirst(count)=fst_dt;&lt;BR /&gt;&amp;nbsp; oldlast(count)=lst_dt;&lt;BR /&gt;&amp;nbsp; hospit(count)=hosp;&lt;BR /&gt;&amp;nbsp; if last.id then output; &lt;BR /&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data adm_dich;&lt;BR /&gt;&amp;nbsp; set hospb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array admissiondt(4) fst_dt1-fst_dt4;&lt;BR /&gt;&amp;nbsp; array dichargedt(4) lst_dt1-lst_dt4;&lt;BR /&gt;&amp;nbsp; array hospitA (4) hosp_1-hosp_4;&lt;BR /&gt;&amp;nbsp; do i =1 to 3;&lt;BR /&gt;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;BR /&gt;&amp;nbsp; if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;BR /&gt;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then disch_dt=dichargedt(i); &lt;BR /&gt;&amp;nbsp; end; &lt;BR /&gt; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; proc print; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format fst_dt1-fst_dt4 lst_dt1-lst_dt4 date0 adm_dt disch_dt date9.;&lt;BR /&gt;&amp;nbsp; run;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 22:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45670#M9446</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-10T22:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45671#M9447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First, welcome to the forum.&amp;nbsp; Most of us are just SAS users like you and it really helps to see the whole problem up front.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have conflicting assignments.&amp;nbsp; Why not just have 3 adm and disch dates?&amp;nbsp; BTW, I added else conditions to your if statements.&amp;nbsp; Doesn't affect the logic, but does speed up performance a bit.&amp;nbsp; E.g.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data adm_dich;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hospb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array admissiondt(4) fst_dt1-fst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dichargedt(4) lst_dt1-lst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospitA (4) hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array adm_dt(3);&lt;/P&gt;&lt;P&gt;&amp;nbsp; array disch_dt(3);&lt;/P&gt;&lt;P&gt;&amp;nbsp; format adm_dt: disch_dt: date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i =1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=1 then adm_dt(i)=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt(i)=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then disch_dt(i)=dichargedt(i); &lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print; &lt;/P&gt;&lt;P&gt;&amp;nbsp; format fst_dt1-fst_dt4 lst_dt1-lst_dt4 date0 adm_dt disch_dt date9.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 22:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45671#M9447</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-10T22:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45672#M9448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just noticed that you only wanted the first one.&amp;nbsp; Do you only want the first one of either adm or discharge, or the first of both.&amp;nbsp; The following gets the first of both:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data adm_dich;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hospb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array admissiondt(4) fst_dt1-fst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dichargedt(4) lst_dt1-lst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospitA (4) hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format adm_dt: disch_dt: date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i =1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(adm_dt) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(disch_dt) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then disch_dt=dichargedt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 23:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45672#M9448</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-10T23:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45673#M9449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Great, that actually was my next question. I really appreciate your help. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 23:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45673#M9449</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-10T23:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45674#M9450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Great thanks to you for all you help. I do have another quick question. In case where 1 is preceded by 0 I need to assign the second date to the admission date, but I think having it set to missing prevent it from doing so. &lt;/P&gt;&lt;P&gt;Below is the updated code for your review. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data adm_dich;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set hospb;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array admissiondt(4) fst_dt1-fst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array dichargedt(4) lst_dt1-lst_dt4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array hospitA (4) hosp_1-hosp_4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format adm_dt: disch_dt: date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i =1 to 3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(adm_dt) then do;&lt;BR /&gt;&amp;nbsp; if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if hospitA&lt;I&gt;=1 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then adm_dt=admissiondt(i);&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(disch_dt) then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hospitA&lt;I&gt;=1 and hospitA[i+1]=0 then disch_dt=dichargedt(i);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else if hospitA&lt;I&gt;=1 and hospitA[i+1]=. then disch_dt=dichargedt(i);&lt;/I&gt;&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc print; &lt;/P&gt;&lt;P&gt;&amp;nbsp; format fst_dt1-fst_dt4 lst_dt1-lst_dt4 date0 adm_dt disch_dt date9.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 00:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45674#M9450</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-11T00:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45675#M9451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure what you are asking.&amp;nbsp; Your question concerned a 0 then 1 combination, but your added code is looking for a 1 then missing combo.&amp;nbsp; You also said that you wanted the second date, but never asked for dischargedt(i+1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statements could be combined:&lt;/P&gt;&lt;P style="background-color: #eef4f9;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if hospitA&lt;I&gt;=1 and (hospitA[i+1]=0 or missing(hospitA[i+1])) then disch_dt=dichargedt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #eef4f9;"&gt;However, again, I'm not sure what you are asking.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 01:52:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45675#M9451</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-11T01:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45676#M9452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for you continuing support. Everything seems to be working great, except the case for admission date where 0 is followed by 1.&lt;/P&gt;&lt;P&gt;if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;In this instance admission date is assigned to the one corresponding to 0 and not to 1. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 17:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45676#M9452</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-11T17:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45677#M9453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I replied to that yesterday.&amp;nbsp; If you want the 2nd date to be assigned then you have to state it in your code.&amp;nbsp; i.e.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if hospitA&lt;I&gt;=0 and hospitA[i+1]=1 then adm_dt=admissiondt(i+1);&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that isn't what you mean, then I don't understand what you are asking.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 17:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45677#M9453</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-11-11T17:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: limit array to look at the first occurence of event</title>
      <link>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45678#M9454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks, I will try that. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Nov 2011 17:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/limit-array-to-look-at-the-first-occurence-of-event/m-p/45678#M9454</guid>
      <dc:creator>natsd</dc:creator>
      <dc:date>2011-11-11T17:56:50Z</dc:date>
    </item>
  </channel>
</rss>

