DATA Step, Macro, Functions and more

To find the last.Last.ReportDateIST

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

To find the last.Last.ReportDateIST

Sir , i want to find last.Last.ReportDateIST,

 

when i submit this code its not happning 

 

data have;
input DumpKey AccountNumber DOSDateKey ReportDateIST ISTProductionDateKey BalanceAmount;
cards;
1012 1012-44340 20160723 2016-08-24 20160808 680.00
1012 1012-44340 20160723 2016-09-04 20160829 680.00
1012 1022-50216 20160808 2016-08-28 20160822 260.00
1012 1022-50216 20160808 2016-09-04 20160822 260.00
1012 1022-50216 20160808 2016-09-11 20160822 260.00
1012 1022-50216 20160808 2016-09-18 20160822 260.00
1012 1025-52296 20160613 2016-08-24 20160809 50.00
1012 1025-52296 20160613 2016-08-28 20160824 50.00
1012 1025-52296 20160613 2016-09-04 20160824 50.00
1012 1025-52296 20160613 2016-09-11 20160906 50.00
1012 1028-54976 20160812 2016-09-04 20160829 275.00
1012 1028-54976 20160812 2016-09-11 20160829 275.00
1012 1028-54976 20160812 2016-09-18 20160829 275.00
1012 1030-45842 20160831 2016-09-18 20160912 400.00
1012 1031-9713 20160720 2016-08-24 20160802 260.00
1012 1034-24465 20160817 2016-09-04 20160829 545.00
1012 1034-24465 20160817 2016-09-11 20160906 545.00
1012 1035-55036 20160816 2016-09-04 20160829 600.00
1012 1035-55036 20160816 2016-09-11 20160829 600.00
1012 1035-55036 20160816 2016-09-18 20160829 600.00
1012 1038-52437 20160615 2016-08-24 20160718 150.00
1012 1038-52437 20160615 2016-08-28 20160718 150.00
1012 1038-52437 20160615 2016-09-04 20160718 150.00
1012 1038-52437 20160615 2016-09-11 20160718 150.00
1012 1038-52437 20160615 2016-09-18 20160718 150.00
1012 1051-9319 20160802 2016-08-24 20160816 510.00
1012 1051-9319 20160802 2016-09-04 20160829 510.00
1012 1074-14760 20160816 2016-09-04 20160829 460.00
1012 1074-14760 20160816 2016-09-11 20160906 460.00
1012 1077-11576 20160611 2016-08-24 20160818 75.00
;
run;

 

 

PROC SORT DATA=Have;
BY DUMPKEY ACCOUNTNUMBER DOSDATEKEY REPORTDATEIST ISTPRODUCTIONDATEKEY;
RUN;

 

DATA Want;
SET Have;
BY DUMPKEY ACCOUNTNUMBER DOSDATEKEY REPORTDATEIST ISTPRODUCTIONDATEKEY;

IF LAST.REPORTDATEIST THEN
OUTPUT;
RUN;


Accepted Solutions
Solution
‎09-19-2016 07:58 AM
Super User
Posts: 7,760

Re: To find the last.Last.ReportDateIST

Posted in reply to sivastat08

PLEASE take ONE little look at your log. Your have dataset is not created with meaningful dates.

 

I guess your INPUT should look like that:

input DumpKey AccountNumber $ DOSDateKey ReportDateIST :YYMMDD10. ISTProductionDateKey BalanceAmount;

And you won't get less than the original 30 observations, as there are no repeats of all your BY variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎09-19-2016 07:58 AM
Super User
Posts: 7,760

Re: To find the last.Last.ReportDateIST

Posted in reply to sivastat08

PLEASE take ONE little look at your log. Your have dataset is not created with meaningful dates.

 

I guess your INPUT should look like that:

input DumpKey AccountNumber $ DOSDateKey ReportDateIST :YYMMDD10. ISTProductionDateKey BalanceAmount;

And you won't get less than the original 30 observations, as there are no repeats of all your BY variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 61

Re: To find the last.Last.ReportDateIST

Posted in reply to KurtBremser

I have Handled - 

 

ReportDateIST as a character string   $10. format  like "2016-08-24"

 

ISTProductionDateKey as a Numaric  11.  format  like "20160808"

 

how should i resolve this .

 

should i change any format thing.

 

 

Super User
Posts: 7,760

Re: To find the last.Last.ReportDateIST

Posted in reply to sivastat08

Since you have several obvious dates in your data, I'd read them all into SAS date values:

 

input DumpKey AccountNumber $ DOSDateKey :yymmdd8. ReportDateIST :YYMMDD10. ISTProductionDateKey :yymmdd8. BalanceAmount;
format DOSDateKey ReportDateIST ISTProductionDateKey yymmddd10.;

This then enables correct sorting etc.

 

What would your wanted output dataset look like?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 61

Re: To find the last.Last.ReportDateIST

Posted in reply to KurtBremser

For the combination  (ACCOUNTNUMBER  DOSDATEKEY  REPORTDATEIST  ISTPRODUCTIONDATEKEY), i want to find last Lastreportdate - Last.REPORTDATEIST thats it.

 

Siva

Super User
Posts: 7,760

Re: To find the last.Last.ReportDateIST

[ Edited ]
Posted in reply to sivastat08

Sort

by ACCOUNTNUMBER  DOSDATEKEY  REPORTDATEIST;

and then use

BY ACCOUNTNUMBER  DOSDATEKEY  REPORTDATEIST;
if last.REPORTDATEIST;

in the data step.

If that does not get your intended result, then you need to post the example of your wanted dataset to illustrate your requirement.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 293 views
  • 2 likes
  • 2 in conversation