BookmarkSubscribeRSS Feed
anirudhs
Obsidian | Level 7

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.

4 REPLIES 4
Satish_Parida
Lapis Lazuli | Level 10

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;
ballardw
Super User

@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.

 

anirudhs
Obsidian | Level 7
sorry for this ... yes i want on the base of datetime values.
Satish_Parida
Lapis Lazuli | Level 10
Have you seen the solution provided based on datetime and your requirement?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 918 views
  • 0 likes
  • 3 in conversation