BookmarkSubscribeRSS Feed
mpajoh
Fluorite | Level 6
I have data set with SAS date variable spanning several years.
I want to create a variable that contains the year and the quarter (e.g 2010Q2), which can then be used to sort by.

Can anyone help?

Masoud
7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
Read about the various YYQ formats. For example, a SAS date value for 03/15/2006 could be used to create a character variable called QTRVAL with this code:
[pre]
qtrval = put(date,yyq6.);
[/pre]

And the resulting value would be: 2006Q1

The documentation on the various formats is here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...

cynthia
mpajoh
Fluorite | Level 6
Thanks Cynthia.
Peter_C
Rhodochrosite | Level 12
Masoud

what difference do you expect when sortng by (internal) sas date and sorting by quarter?

just interested
Peterc
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With a multiple-variable BY statement, the order of observations that have date values throughout a given quarter, may get sorted differently if only considering the "formatted" value sort-sequence, presuming the BY statement has additional variables to the right of the date variable itself.

Scott Barry
SBBWorks, Inc.
mpajoh
Fluorite | Level 6
I am using the quarter variable to for proc summary's class variable.

Masoud
data_null__
Jade | Level 19
You can use the CLASS statement option GROUPINTERNAL to have you cake and eat it too.
mpajoh
Fluorite | Level 6
Thank you all.
I will have to investigate and learn.

Masoud

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 2074 views
  • 0 likes
  • 5 in conversation