BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

7 REPLIES 7
art297
Opal | Level 21

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

 

Art, CEO, AnalystFinder.com

 

ballardw
Super User

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?

DavidPhillips2
Rhodochrosite | Level 12

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.

art297
Opal | Level 21

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

 

DavidPhillips2
Rhodochrosite | Level 12

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

 

put(datepart(wrs_date), yymmdd10.)

Reeza
Super User

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

Reeza
Super User

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;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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