DATA Step, Macro, Functions and more

How to flag the latest date or use group by

Reply
Contributor
Posts: 70

How to flag the latest date or use group by

Hi I want to use the following dates and the record associated with it following is the data

 

CASE_ID,Activity_Creator,Decisioned_By,comment,Suspect_Reason,Agency_Date
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:35:14.00
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:33:00.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,SALARY SLIP VERIFICATION,01NOV2017:15:33:41.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,VERIFICATION OF SALARY SLIP,01NOV2017:15:40:11.00

 

need to fetch only the dates and records associated with that date in red. 

Also need to know how can we flag it as 1 and the same date with least time as 0 

 

and how can we use group by statement in querry builder and base.

Frequent Contributor
Posts: 112

Re: How to flag the latest date or use group by

I have used sql same can be done in data step using group by and first or last clause.

 

data have;
infile datalines dsd truncover;
input CASE_ID Activity_Creator:$30. Decisioned_By:$40. Suspect_Reason:$40. Agency_Date:datetime21.;
format Agency_Date datetime21.;
datalines;
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:35:14.00
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:33:00.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,SALARY SLIP VERIFICATION,01NOV2017:15:33:41.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,VERIFICATION OF SALARY SLIP,01NOV2017:15:40:11.00
;
run;

proc sql;
create table want as
select a.* 
from have a, 
	(select CASE_ID,max(Agency_Date) as dtm from have group by CASE_ID) b 
where  a.CASE_ID=b.CASE_ID and a.Agency_Date=b.dtm;
quit;
Super User
Posts: 13,939

Re: How to flag the latest date or use group by


anirudhs wrote:

Hi I want to use the following dates and the record associated with it following is the data

 

CASE_ID,Activity_Creator,Decisioned_By,comment,Suspect_Reason,Agency_Date
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:35:14.00
25412,RAPID INVESTIGATION SERVICES,Agency,CREDIT REFER,06FEB2018:15:33:00.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,SALARY SLIP VERIFICATION,01NOV2017:15:33:41.00
14284,SHARP EAGLE INVESTIGATION PVT LTD,Agency,VERIFICATION OF SALARY SLIP,01NOV2017:15:40:11.00

 

need to fetch only the dates and records associated with that date in red. 

Also need to know how can we flag it as 1 and the same date with least time as 0 

 

and how can we use group by statement in querry builder and base.


Just to share a pet peeve: Those highlighted values are not dates they are datetime values. With SAS data this is important as datetimes are measured in seconds and dates are measure in days. If you apply DATE functions, such as Year, moth, day or such intervals with functions like intnx or intck then the results are usually incredibly wrong. So using the proper DATETIME terminology will yield suggestions using the appropriate functions or parameters.

 

And consider you have said "fetch only the dates and records associated with that date in red". so for 01NOV2017:15:40:11.00

do you also want the value if the "date" is 01NOV2017:13:21:11.00 or not for that id value? If not then the TIME of day is important.

But since you said "date" I would expect you to be requesting all the values for the DATE portion of the variable.

 

Contributor
Posts: 70

Re: How to flag the latest date or use group by

sorry for this ... yes i want on the base of datetime values.
Frequent Contributor
Posts: 112

Re: How to flag the latest date or use group by

Have you seen the solution provided based on datetime and your requirement?
Ask a Question
Discussion stats
  • 4 replies
  • 87 views
  • 0 likes
  • 3 in conversation