Solved
Valued Guide
Posts: 620

# 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
Super User
Posts: 8,220

## 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

All Replies
Super User
Posts: 8,220

## 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: 13,950

## 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?

Valued Guide
Posts: 620

## 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
Super User
Posts: 8,220

## 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

Valued Guide
Posts: 620

## Re: Grouping by Day from Date

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

put(datepart(wrs_date), yymmdd10.)

Super User
Posts: 24,027

## 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: 24,027

## 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 and locked.