<?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 determine the active record for the last month? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516367#M139461</link>
    <description>&lt;P&gt;The below code is one possible way of solving your problem. You will have to adapt it for your specific use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*create some fake dates as examples*/
data have;
attrib randomdate format = ddmmyys10.;
do randomdate = "1JAN2018"d to "1JAN2019"d by 14;
	output;
end;
run;

/*I want the dates in the most recent order first
so that when i select the first observation it is the most recent*/
proc sort 	data = have
			out = havesorted;
by descending randomdate;
run;

/*Two different datasets both using the same style,
they will return everything from the table for the observation requested
If you want different date just change the date in the where clause.
*/
data wantToday;
set havesorted(obs = 1 where = ( randomdate lt today() ));
run;

data wantOld;
set havesorted(obs = 1 where = ( randomdate lt "1MAR2018"d ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Nov 2018 16:09:06 GMT</pubDate>
    <dc:creator>DanielLangley</dc:creator>
    <dc:date>2018-11-27T16:09:06Z</dc:date>
    <item>
      <title>How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516299#M139437</link>
      <description>&lt;P&gt;I've a data as mentioned below&amp;nbsp;in which I'm applying filter (current_ind=1) to determine the active record for the current month. If I run the DI job for this month, I will get only the last record from the below data in my output. However If I run the job for March, I should get the last before record &amp;nbsp;(where &lt;SPAN&gt;POLICY_VERSION_ISSUE_DT&lt;/SPAN&gt;=&lt;SPAN&gt;20/feb/18&lt;/SPAN&gt;)in my output. That was the record which was active during March. I guess CURRENT_IND and&amp;nbsp;&lt;SPAN&gt;POLICY_VERSION_ISSUE_DT is clue to determine the record for my output when I run the job for the past time periods. Could you please help me with the condition to determine the active policy for the past time periods? Please ignore the format issue in&amp;nbsp;POLICY_VERSION_ISSUE_DT.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I run the job as follows in Putty. First script is for current time period and the other one is for March.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sh jobskeleton_std_01.sh uds_ex_details_tbfr10_13_50&amp;nbsp; D20181127:00:00:00*N*N uds_ex_details_tbfr10_13_50.log&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;sh jobskeleton_std_01.sh uds_ex_details_tbfr10_13_50&amp;nbsp; D20180327:00:00:00*N*N uds_ex_details_tbfr10_13_50.log&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="864"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;POLICY_ID&lt;/TD&gt;
&lt;TD width="133"&gt;VALID_FROM_DTTM&lt;/TD&gt;
&lt;TD width="133"&gt;VALID_TO_DTTM&lt;/TD&gt;
&lt;TD width="133"&gt;PROCESSED_DTTM&lt;/TD&gt;
&lt;TD width="95"&gt;CURRENT_IND&lt;/TD&gt;
&lt;TD width="180"&gt;POLICY_VERSION_ISSUE_DT&lt;/TD&gt;
&lt;TD width="113"&gt;POLICY_VERSION&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:03&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:03&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;05/aug/15&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:04&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:04&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;15/jun/17&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:05&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:05&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;24OCT2017&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:06&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:06&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;16/nov/17&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:07&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:07&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;02/dec/17&lt;/TD&gt;
&lt;TD&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:08&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:08&lt;/TD&gt;
&lt;TD&gt;17MAY2018:13:00:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;18/jan/18&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;17MAY2018:00:00:09&lt;/TD&gt;
&lt;TD&gt;26OCT2018:23:59:59&lt;/TD&gt;
&lt;TD&gt;28OCT2018:19:10:00&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;20/feb/18&lt;/TD&gt;
&lt;TD&gt;9&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2011077371&lt;/TD&gt;
&lt;TD&gt;27OCT2018:00:00:00&lt;/TD&gt;
&lt;TD&gt;31DEC4747:23:59:59&lt;/TD&gt;
&lt;TD&gt;28OCT2018:19:10:00&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;26OCT2018&lt;/TD&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 13:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516299#M139437</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-27T13:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516367#M139461</link>
      <description>&lt;P&gt;The below code is one possible way of solving your problem. You will have to adapt it for your specific use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*create some fake dates as examples*/
data have;
attrib randomdate format = ddmmyys10.;
do randomdate = "1JAN2018"d to "1JAN2019"d by 14;
	output;
end;
run;

/*I want the dates in the most recent order first
so that when i select the first observation it is the most recent*/
proc sort 	data = have
			out = havesorted;
by descending randomdate;
run;

/*Two different datasets both using the same style,
they will return everything from the table for the observation requested
If you want different date just change the date in the where clause.
*/
data wantToday;
set havesorted(obs = 1 where = ( randomdate lt today() ));
run;

data wantOld;
set havesorted(obs = 1 where = ( randomdate lt "1MAR2018"d ));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516367#M139461</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2018-11-27T16:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516576#M139538</link>
      <description>&lt;P&gt;Any other alternative way to achieve this?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 05:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516576#M139538</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-28T05:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516602#M139545</link>
      <description>&lt;P&gt;There are probably 100 different ways to solve this problem. Why exactly does this solution not work? Do you need it to be faster? To not sort the data?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 10:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516602#M139545</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2018-11-28T10:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516633#M139555</link>
      <description>&lt;P&gt;yes, I no need to sort the data.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 12:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516633#M139555</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-11-28T12:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine the active record for the last month?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516657#M139568</link>
      <description>&lt;P&gt;If you cannot sort your data there is a deeper problem. I would also have a look into that if I were you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
attrib randomdate format = ddmmyys10.;
retain PolicyNumber 0;
do randomdate = "1JAN2018"d to "1JAN2019"d by 14;
	PolicyNumber + 1;
	output;
end;
run;


proc sql;
create table work.want as
select have.*
from work.have
where randomdate lt today()
having max(PolicyNumber) = PolicyNumber
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Yes this is still doing some sorting behind the scenes but if you are using the pass-through facility it might be easier on your machine. If this does not work then you would have to look at the data itself and why it cannot be sorted. Maybe post some specifics and a more experienced programmer could help you out.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 13:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-determine-the-active-record-for-the-last-month/m-p/516657#M139568</guid>
      <dc:creator>DanielLangley</dc:creator>
      <dc:date>2018-11-28T13:32:25Z</dc:date>
    </item>
  </channel>
</rss>

