<?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: Determine result across multiple records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/456245#M284202</link>
    <description>&lt;P&gt;I don't think I asked my question correctly. This is what I need to do......some school districts run multiple referenda to get authority to raise taxes. Some district fail, then subsequently&amp;nbsp;pass a&amp;nbsp;referendum. Base on testing if this did occur,&amp;nbsp;they then get additional other taxing authority.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to determine,&amp;nbsp;for each entity that has both passed and failed a referendum in the past 3&amp;nbsp;years (so, the entity will&amp;nbsp;have&amp;nbsp;multiple records, one each for each attempted referendum), if the date of the "passed" referendum is more recent than that of the failed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to test each record and get a numeric result so&amp;nbsp;I can then&amp;nbsp;combine all the records into 1 record for the entity (which I will do with proc summary) to&amp;nbsp;make comparisons within the entity&amp;nbsp;record to see if there was a fail/pass situation, as opposed to trying to compare&amp;nbsp;across multiple records. I have never worked with more than one record per entity, so this is causing me a bit of grief.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to&amp;nbsp;assign a "1" to each passed/failed response so then I can use the proc summary. For the entity 14 below, I&amp;nbsp;should get a 3 in the failed field (after the proc summary) because they had 3 failed referenda. (My second problem is converting dates from an oracle database so SAS&amp;nbsp;can compare and rank in chronological order.....)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have the loop code I used with me at home right now but it's not working anyhow.....I&amp;nbsp;am&amp;nbsp;getting (for entity 14, let's say)&amp;nbsp; not only the counts for the entity 14 (which should be 3&amp;nbsp;failed), I was also getting counts for "passed" from the previous record in the summary record. (proc summary is by entity)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think they call this control break processing and I need to clear the fields with each new entity, but it's not working....I think the code is not too complex, but I don't have much experience. Thoughts on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;entity&lt;/TD&gt;&lt;TD&gt;vote date&lt;/TD&gt;&lt;TD&gt;passed&lt;/TD&gt;&lt;TD&gt;failed&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10/25/2015&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1/18/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10/18/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;2/16/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;8/26/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;9/15/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Apr 2018 01:15:49 GMT</pubDate>
    <dc:creator>Karenk1</dc:creator>
    <dc:date>2018-04-22T01:15:49Z</dc:date>
    <item>
      <title>Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/454529#M284200</link>
      <description>&lt;P&gt;Usually work with 1 record per entity. Not a frequent SAS user.........I've tried everything I know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have multiple records for each entity. Each record has a field(s) that has been assigned a Y or N based on certain criteria.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given that SAS processes 1 record at a time, how can I test "across records" to get a single result? For instance, if a field in record number 1 = N and a different field from record 2 = N...........&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;school code, referendum date, referendum type and result&lt;/P&gt;&lt;P&gt;0007, 8/5/2016, operating_referendum_passed_flag = N&lt;/P&gt;&lt;P&gt;0007, 10/19/2017, debt_referendum_passed_flag = N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version 9.1&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;</description>
      <pubDate>Mon, 16 Apr 2018 18:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/454529#M284200</guid>
      <dc:creator>Karenk1</dc:creator>
      <dc:date>2018-04-16T18:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/454541#M284201</link>
      <description>&lt;P&gt;Separate type and result. Then you can manipulate. For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd;
input code $ date :anydtdte10. type_result :$64.;
format date yymmdd10.;
length type $40 result $1;
type = scan(type_result,1,"=");
result = strip(scan(type_result,2,"="));
drop type_result;
datalines;
0007, 8/5/2016, operating_referendum_passed_flag = N
0007, 10/19/2017, debt_referendum_passed_flag = N
;

proc sql;
create table o_d_cases as
select 
    o.code,
    o.date as o_date,
    o.result as o_result,
    d.date as d_date,
    d.result as d_result
from
    have as o inner join 
    have as d on o.code = d.code and o.date &amp;lt; d.date
where o.type = "operating_referendum_passed_flag" and
    d.type = "debt_referendum_passed_flag";
title "Operating - debt cases"; 
select * from o_d_cases;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 18:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/454541#M284201</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-04-16T18:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/456245#M284202</link>
      <description>&lt;P&gt;I don't think I asked my question correctly. This is what I need to do......some school districts run multiple referenda to get authority to raise taxes. Some district fail, then subsequently&amp;nbsp;pass a&amp;nbsp;referendum. Base on testing if this did occur,&amp;nbsp;they then get additional other taxing authority.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to determine,&amp;nbsp;for each entity that has both passed and failed a referendum in the past 3&amp;nbsp;years (so, the entity will&amp;nbsp;have&amp;nbsp;multiple records, one each for each attempted referendum), if the date of the "passed" referendum is more recent than that of the failed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to test each record and get a numeric result so&amp;nbsp;I can then&amp;nbsp;combine all the records into 1 record for the entity (which I will do with proc summary) to&amp;nbsp;make comparisons within the entity&amp;nbsp;record to see if there was a fail/pass situation, as opposed to trying to compare&amp;nbsp;across multiple records. I have never worked with more than one record per entity, so this is causing me a bit of grief.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to&amp;nbsp;assign a "1" to each passed/failed response so then I can use the proc summary. For the entity 14 below, I&amp;nbsp;should get a 3 in the failed field (after the proc summary) because they had 3 failed referenda. (My second problem is converting dates from an oracle database so SAS&amp;nbsp;can compare and rank in chronological order.....)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't have the loop code I used with me at home right now but it's not working anyhow.....I&amp;nbsp;am&amp;nbsp;getting (for entity 14, let's say)&amp;nbsp; not only the counts for the entity 14 (which should be 3&amp;nbsp;failed), I was also getting counts for "passed" from the previous record in the summary record. (proc summary is by entity)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think they call this control break processing and I need to clear the fields with each new entity, but it's not working....I think the code is not too complex, but I don't have much experience. Thoughts on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;entity&lt;/TD&gt;&lt;TD&gt;vote date&lt;/TD&gt;&lt;TD&gt;passed&lt;/TD&gt;&lt;TD&gt;failed&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10/25/2015&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;1/18/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;10/18/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;2/16/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;8/26/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;9/15/2017&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 01:15:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/456245#M284202</guid>
      <dc:creator>Karenk1</dc:creator>
      <dc:date>2018-04-22T01:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Determine result across multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/456620#M284203</link>
      <description>&lt;P&gt;First, I would suggest you to read in the dates using an informat&amp;nbsp;like below, since you will need to compare dates in the process.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;:mmddyy10.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is your data recreated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   infile datalines missover dsd dlm=' ';
   input entity vote_date :mmddyy10. passed $ failed $;
datalines;
7 10/25/2015 Y 
7 1/18/2016  Y
7 10/18/2016  Y
14 2/16/2017  Y
14 8/26/2017  Y
14 9/15/2017  Y
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use a RETAIN statement to keep track of the most recent date for passed and failed&amp;nbsp;&lt;SPAN&gt;referendum&amp;nbsp;(I used&lt;/SPAN&gt; lastpassed_date and lastfailed_date to hold their values).&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 test2;
   set test;
   by entity vote_date;
   retain lastpassed_date lastfailed_date;

   if first.entity then do;
      lastpassed_date=.;
      lastfailed_date=.;
   end;
   if passed='Y' then lastpassed_date=vote_date;
   else if failed='Y' then lastfailed_date=vote_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now that you have these dates stored, you can compare&amp;nbsp;them at the end of the program. Sounds like you might only want to keep the records where lastpassed_date is greater than lastfailed_date, making sure to check that lastfailed_date isn't missing.&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;if lastpassed_date &amp;gt; lastfailed_date and not missing(lastfailed_date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let me know if this works.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 17:37:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-result-across-multiple-records/m-p/456620#M284203</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2018-04-23T17:37:41Z</dc:date>
    </item>
  </channel>
</rss>

