BookmarkSubscribeRSS Feed
mdavidson
Quartz | Level 8
Hello all,

I just started using SAS at work and have been learning on my own for a few weeks before we get sent off to formal training. The question that I have is how can I group by a formatted date The field that I have is a date time field, and what I want to do is group that date by YYYYMMs format. Once my date is in the proper format, I'm unable to group by that format; SAS seems to revert back to the field's original format despite showing it in the format that I desire.

The only way I have gotten around this is to turn my date field into YYYMMs as a character field, but the obviously I lose some date functionality. Any suggestions?
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
Some SAS procedures use the formats, others ignore them. So the answer is: It depends.

For instance, PROC MEANS uses formats for the CLASS statement but not for the VAR statement. FREQ uses them throughout. REG ignores them for continuous variables. The DATA step generally ignores formats in expressions, but there are functions to allow you to get the formatted value [PUT(varname, format.), for instance].

You probably need to read the chapters on Dates and formats in the Base manual and scan the procedure manuals for 'format' in the PROC chapters that are of interest. For us to provide more specific suggestions, we'll need a more specific question.
rab24
Calcite | Level 5
For grouping purposes, I just create a new variable to restrict my data.

Something like

intnx("Month",mydate,0)

will change 17Jun2008 to 1Jun2008. You will lose the day specific information, but when you format it as 200806, you will know that all the 200806 records will be grouped together.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 793 views
  • 0 likes
  • 3 in conversation