DATA Step, Macro, Functions and more

Grouping by Day from Date

Accepted Solution Solved
Reply
Super Contributor
Posts: 480
Accepted Solution

Grouping by Day from Date

How do you group by a day from a date so you can display a group by a particular date?  Surprisingly this is hard to Google.


Accepted Solutions
Solution
‎05-08-2017 03:34 PM
PROC Star
Posts: 7,363

Re: Grouping by Day from Date

You can use the datepart() function to extract date from a datetime stamp and then us proc freq of date (or get the counts from proc means/summary or proc sql) to get the number of entries per day.

 

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
PROC Star
Posts: 7,363

Re: Grouping by Day from Date

Can you provide an example of what you are trying to achieve?

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 10,508

Re: Grouping by Day from Date

Generally when I here "group" and  "date" then I think of formats. Can you provide an example of the dates you have and the "group" you need?

Are you attempting to assign a group, create a new variable, or just use the group in an procedure?

Super Contributor
Posts: 480

Re: Grouping by Day from Date

I’m looking a log table with one entry per time a user accesses an application, with a date time stamp.  I am trying to view the number of times a user accesses the application per day.

Solution
‎05-08-2017 03:34 PM
PROC Star
Posts: 7,363

Re: Grouping by Day from Date

You can use the datepart() function to extract date from a datetime stamp and then us proc freq of date (or get the counts from proc means/summary or proc sql) to get the number of entries per day.

 

Art, CEO, AnalystFinder.com

 

Super Contributor
Posts: 480

Re: Grouping by Day from Date

Art297 thank you, I was able to use date part.

 

put(datepart(wrs_date), yymmdd10.)

Super User
Posts: 17,840

Re: Grouping by Day from Date

You shouldn't do the PUT() part, IMO. That converts it to a character field. Although it will sort correctly because you've used YYMMDD, it's easier to just use a SAS date .

 

 

datepart(wrs_date) format=yymmdd10. as ...

Super User
Posts: 17,840

Re: Grouping by Day from Date

As indicated, apply the correct format, DTDATE9. can be used without creating a new variable. Note that PROC SQL does not respect formats so this type of summary cannot be done in SQL without creating the new variable.

 

proc freq data=sample noprint;
format datetime_var dtdate9.;

table date*user/out=summary;
run;
☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 122 views
  • 4 likes
  • 4 in conversation